Question

I'm writing a a php script where i do a loop and inside the loop there is a particular function processing information, as illustrated here.

while (some condition){
    // some code
    processInformation();
    // Some more code
}

Well it turns out that midway, inside processInformation(), I encountered the error Fatal error: Maximum execution time of 30 seconds exceeded. Using set_time_limit(0), would not help in my situation because processInformation() might take forever. I don't want an error to completely break my program, so is there anyway i can catch an exception or tell php to "continue" the loop if processInformation() takes too long?

No correct solution

OTHER TIPS

You can increase the value of maximum execution time from 30 seconds to any value. For example: if you want to set the limit of maximum execution time of 3 minutes (instead of 30 seconds), then you can set as:

ini_set('max_execution_time', 180); //maximum execution time of 3 minutes

This way, you can set the time based on your need.

I dunno how to catch the exception but you could use a simple time calculation to escape after say 60 secs. ()

$x=time();
while (some condition){

    processInformation();

    if ($x + 60) < time() 
    break;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top