According to a comment in the manual on register_shutdown_function()
, this can be done the following way:
When using CLI ( and perhaps command
line without CLI - I didn't test it)
the shutdown function doesn't get
called if the process gets a SIGINT or
SIGTERM. only the natural exit of PHP
calls the shutdown function. To
overcome the problem compile the
command line interpreter with
--enable-pcntl
and add this code:
<?php
function sigint() {
exit;
}
pcntl_signal(SIGINT, 'sigint');
pcntl_signal(SIGTERM, 'sigint');
?>
This way when the process recieves one
of those signals, it quits normaly,
and the shutdown function gets called. ... (abbreviating to save space, read the full text)
If that is too much hassle, I would consider doing the timing out from within PHP by setting a time limit instead. Reaching the limit will throw a fatal error, and the shutdown function should get called normally.