PHP Fatal Error not being caught
simon.facciol
Posted on
Jan 29 2015
Hi,
I have just integrated Raygun into my Zend application and I get some of the PHP errors logged into Raygun, but somehow PHP Fatal errors are not being logged.
Could you recommend the best way to integrate Raygun with Zend? I guess that the PHP Fatal error is being fired before Raygun is actually loaded, but I am initialising Raygun in the Bootstrap.php file.
Thanks!
simon.facciol
Posted on
Jan 29 2015
So I managed to find out that a different handler needs to be registered for these kind of errors:
register_shutdown_function("fatal_handler");
And now it works. Just use the following handler or something similar.
function fatal_handler()
{
global $raygunClient;
$errfile = "unknown file";
$errstr = "shutdown";
$errno = E_CORE_ERROR;
$errline = 0;
$error = error_get_last();
if( $error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
$raygunClient->SendError($errno, $errstr, $errfile, $errline);
error_log('Sent fatal');
}
}
Callum
Posted on
Jan 30 2015
Glad to hear you got it working. That's a succinct code snippet, if you like we can add it to the PHP docs so others can benefit from your findings. We'll also be considering adding in dedicated support to pick up these fatal errors automatically in V2 of the provider. Thanks for using Raygun!
simon.facciol
Posted on
Jan 30 2015
Hi.
Yes feel free to use the code however you like.
I am looking forward to see more features implemented into Raygun, even non-error related features.