Discussion:
What happens when the execution time limit is exceeded?
Tim Streater
2014-03-06 13:23:00 UTC
Permalink
It would seem that exceeding the execution time can be caught by declaring a handler with set_error_handler. However, even though I'm sure I've read something about it somewhere, I can't now find any info about what happens next. Specifically, inside my error handler, how long does the error handler then have to clean up? Can I do set_time_limit() again and return? (not that I'm minded to, but it might be useful to someone).

I seem to have enough time to output some stuff back to the browser and log an error message or two, but it might be useful to know the actual limits.
--
Cheers -- Tim
Christoph Becker
2014-03-06 14:02:04 UTC
Permalink
Post by Tim Streater
It would seem that exceeding the execution time can be caught by
declaring a handler with set_error_handler. However, even though I'm
sure I've read something about it somewhere, I can't now find any
info about what happens next. Specifically, inside my error handler,
how long does the error handler then have to clean up? Can I do
set_time_limit() again and return? (not that I'm minded to, but it
might be useful to someone).
I seem to have enough time to output some stuff back to the browser
and log an error message or two, but it might be useful to know the
actual limits.
You can't catch a timeout with set_error_handler(), because it is a
fatal error. The only option you have is using
register_shutdown_function() (which does not allow to return). It seems
that the registered shutdown function resets the timeout once.

Anyway, it seems better to prolong the timeout limit by calling
set_time_limit() in advance, when you're expecting a long execution time.
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tim Streater
2014-03-06 14:13:00 UTC
Permalink
Post by Christoph Becker
Post by Tim Streater
It would seem that exceeding the execution time can be caught by
declaring a handler with set_error_handler. However, even though I'm
sure I've read something about it somewhere, I can't now find any
info about what happens next. Specifically, inside my error handler,
how long does the error handler then have to clean up? Can I do
set_time_limit() again and return? (not that I'm minded to, but it
might be useful to someone).
I seem to have enough time to output some stuff back to the browser
and log an error message or two, but it might be useful to know the
actual limits.
You can't catch a timeout with set_error_handler(), because it is a
fatal error. The only option you have is using
register_shutdown_function() (which does not allow to return). It seems
that the registered shutdown function resets the timeout once.
Ah, thanks. My shutdown_function in fact calls my error_handler, so that explains it.
Post by Christoph Becker
Anyway, it seems better to prolong the timeout limit by calling
set_time_limit() in advance, when you're expecting a long execution time.
Oddly enough :-) that's actually what I do. But understanding what happens is important.
--
Cheers -- Tim
Continue reading on narkive:
Loading...