Limit execution time of a function/script

learning_brain

New Member
Messages
206
Reaction score
1
Points
0
I have a thumbnail generator that accesses remote files, copies them and then re-sizes before saving the thumbnail locally.

As this is an image search engine, there's a lot to get through!!

My problem is that, although the script is quite tidy and has been optimised as much as I can, I'm still relying on the speed of the image hosting server.

With functions being called like getimagesize() and imagecreatefromjpg(), these can take a while and sometimes, they just hang until the default max execution time kicks in.

Ideally, when the script is looping through each image, I'd like to set a localised timeout which gracefully returns an error (or false) so if one image is taking too long, it can skip to the next loop without the dreaded fatal error.

I've read up on set_time_limit, but I can't see any way to avoid a fatal error.

e.g. my made-up function....

PHP:
do{

if (limit_execution_time(10)){

$image_info = getimagesize($row_img_url);
$thumb = createimagefromjpg($row_img_url);

//more script to process the thumbnail blah de blah

} else {
update_database('Image $row_img_id skipped due to excessive time to process.');
echo "function took too long.  Escaping";
}


} while (there are still images left);

You get the idea - wouldn't this be great!

Any ideas on anything similar?

Rich
 
Top