Is there a way to know the value passed to exit() from within a shutdown function?
For example:
<?php
function handleShutdown(){
// Is there a way to know the value passed to exit() at this point?
someCleanup();
}
register_shutdown_function('handleShutdown');
if(somethingWentWrong()){
exit(3);
}
exit(0);
This is in the context of a complex set of legacy scripts running in CLI mode. I am looking for a solution to instrument their exit status within php that does not involve modifying all the points where the scripts invoke exit() (so, not using a global variable, define or forking the whole script).
There is this other SO question asking to know whether the exit was is "clean", but it does not address the exit code at all.
You can install uopz, which will give you uopz_get_exit_status().
Then use it in your handleShutdown function:
$exitCode = uopz_get_exit_status();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With