/    Sign up×
Community /Pin to ProfileBookmark

My Thumbnail Scraper is exceeding maximum execution time

I want to create a script that can get a thumbnail from an URL. Here’s what I have so far:

[code=php]// Gets the HTML for the URL
$string = FetchPage($link);
if($string){
preg_match_all(‘/<img[^>]*src=[“|’](.*(jpg|jpeg|gif|png))[“|’]/Ui’, $string, $out, PREG_PATTERN_ORDER);
$i=1;
while(1){
// Choose a random image
$num = rand(0,count($out[1]));
$source_image_path = $out[1][$num];
// If the URL is relative
if (stripos($source_image_path,’http’)!=0){
// remove the first slash
if(stripos($source_image_path,’/’)==0)
$source_image_path = substr($source_image_path,1);
// Get directory of the link; creates an absolute URL
$source_image_path = preg_replace(‘//([^/]*)?$/’,”,$link).$source_image_path;
}
if(!url_exists($source_image_path))
continue;
list( $source_image_width, $source_image_height, $source_image_type ) = getimagesize( $source_image_path );
// I don’t want icons
if($source_image_width>30 && $source_image_height>30)
break;
$i++;
if($i>20){
// Taking too long
$source_image_path = false;
break;
}
}
preg_match(‘/([^/]+.w+)(?.+)?$/’,$source_image_path,$matches);
$file_name = $matches[1];
}[/code]

I need $source_image_path and $file_name for later use. How do I prevent this script from taking so long?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @narutodude000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...