Is it possible to invoke a function when a cron process is killed from the command line (via Ctrl+c) or with the kill command?
I have tried register_shutdown_function(), but it doesn’t seem to be invoked when the script is killed, but does get invoked when the script ends normally.
I am trying to log the result to a file and update a database value when a cron instance is killed automatically (ie. has been running too long).
According to a comment in the manual on
register_shutdown_function(), this can be done the following way: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.