How can I log a fatal error occuring within a call_user_func_array?
Its within a CLI script that runs as a daemon.
I would like to log when an error occurs, but instead it always throws the error message back.
things that I tried but couldn’t make it work:
try {call_user_func_array()} catch (Exception $e ) {do_log}
or
ob_start ();
try {call_user_func_array()} catch (Exception $e ) {do_log}
or
register_shutdown_function('shutdownFunction');
or
ini_set('error_log',$baseDir.'/Jobque_error.log');
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
$STDIN = fopen('/dev/null', 'r');
$STDOUT = fopen($baseDir.'/Jobque_application.log', 'ab');
$STDERR = fopen($baseDir.'/Jobque_daemon.log', 'ab');
You cannot catch a fatal error. It is fatal so your script dies and there is nothing you can do about it.
Actually, a function registered via
register_shutdown_handlerwill still execute but you cannot get a backtrace etc. so that’s pretty useless.The only possible logging of a fatal error is via the
log_errorsphp.ini setting.