ShadowMage Posted August 17, 2011 Share Posted August 17, 2011 Hello guys,Quick question. Is it possible to "catch" the maximum execution time exception and send an email if that time limit is reached? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 17, 2011 Share Posted August 17, 2011 I don't think so, but you can get the setting for the max execution time and periodically check how long the script has been running and whether it's in danger of timing out. Link to comment Share on other sites More sharing options...
ShadowMage Posted August 17, 2011 Author Share Posted August 17, 2011 I don't think so, but you can get the setting for the max execution time and periodically check how long the script has been running and whether it's in danger of timing out.That's what I figured the answer would be....:)Unfortunately, I think that would be a real performance killer because nearly the entire script is one loop iterating through a huge chunk of data from a database. I'd have to check the execution time on every iteration and I would think that would take a considerable amount of time and resources. Unless I set some sort of counter to only check the time every 50 iterations or so, but I don't know if that would provide much benefit...Then again, checking the execution time is a pretty trivial calculation, so maybe it wouldn't even affect it....Guess I'll have to benchmark! Link to comment Share on other sites More sharing options...
JamesB Posted August 17, 2011 Share Posted August 17, 2011 What about using register_shutdown_function, this post says the functions still get executed Link to comment Share on other sites More sharing options...
justsomeguy Posted August 18, 2011 Share Posted August 18, 2011 That looks like another option, there's probably a way that you can check inside the shutdown function whether or not the execution time has reached the limit, with global variables if necessary. The performance penalty there would be that the function gets executed and does it check every time regardless of the execution time. You may be able to use this function to get the elapsed time, but it's OS-dependent:http://www.php.net/manual/en/function.getrusage.php Link to comment Share on other sites More sharing options...
ShadowMage Posted August 18, 2011 Author Share Posted August 18, 2011 What about using register_shutdown_function, this post says the functions still get executedThat looks like a viable option. Thank you!@JSGI cannot use the getrusage() function since I am running a Windows server, but I will do some testing to see how the register_shutdown_function function works. Link to comment Share on other sites More sharing options...
ShadowMage Posted August 18, 2011 Author Share Posted August 18, 2011 If your script exceeds the maximum execution time, and terminates thusly:Fatal error: Maximum execution time of 20 seconds exceeded in - on line 12The registered shutdown functions will still be executed.Sadly...this doesn't seem to be the case. It just generates two timeout errors instead of one. One on the line where the script actually timed out, and one on the first line of the registered function. I tried just a plain echo and sending an email. I didn't see any output except the two errors, and I didn't receive an email.I was hopeful but it seems my hopes were dashed.... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.