Created
October 5, 2012 13:47
-
-
Save maxmanders/3839887 to your computer and use it in GitHub Desktop.
PHP Fatal Exception Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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