I have a script which is basically cleaning things up.
One part of the script requires checking if images exist, using file_get_contents
I KNOW this is going to run into problems and I'm going to get Fatal error: Maximum execution time of 30 seconds exceeded
from time to time and want to avoid that.
Is there a way to set a counter that starts counting and if file_get_contents fails after say 25 seconds the script ignores then carries on.
I will say, I know I can but I do not want to increase the time limit.
This is the basic script:
$query = "select table_id, image_url from table";
$res = $mysqli->query($query) or trigger_error($mysqli->error."[$query]");
while($row = $res->fetch_array()){
// save the image
$img = '/path/to/'.$row[table_id].'.jpg';
//## need to start counting to 25 secs here
$saveImage = file_put_contents($img, file_get_contents($row[image_ur]));
//## check if 25 seconds realised, if so with no $saveImage then continue
if($saveImage){
// do something else
}
}