Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging error within a call_user_func_array()

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');
like image 684
SunWuKung Avatar asked Feb 25 '26 03:02

SunWuKung


1 Answers

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_handler will 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_errors php.ini setting.

like image 167
ThiefMaster Avatar answered Mar 02 '26 08:03

ThiefMaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!