Skip to content

Instantly share code, notes, and snippets.

@maxmanders
Created October 5, 2012 13:47
Show Gist options
  • Save maxmanders/3839887 to your computer and use it in GitHub Desktop.
Save maxmanders/3839887 to your computer and use it in GitHub Desktop.
PHP Fatal Exception Handler
/*
* Somewhere in their bootstrap code, index.php or wherever, we'd register a shutdown
* callback that is executed when PHP completes serving the request (whether successfully,
* or in the event of a fatal error.
*/
register_shutdown_function('requestShutdown');
function requestShutdown() {
$error = error_get_last();
// Fatal Error
if ($error !== NULL) {
$errorDetails = "[SHUTDOWN] file:"
. $error['file']
. " | line: " . $error['line']
. " | message: " . $error['message']
. PHP_EOL;
openlog("FatalError", LOG_PID | LOG_PERROR, LOG_LOCAL5);
syslog($errorDetails);
closelog();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment