Last active
December 21, 2015 00:09
-
-
Save ravinsharma12345/6218249 to your computer and use it in GitHub Desktop.
Graceful shutdown for php fatal error. When error occurs, get last error and send me and email about it.
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
<?php | |
register_shutdown_error('shutdown_notify'); | |
function shutdown_notify(){ | |
$error = error_get_last(); | |
if(!empty($error) && in_array($error['type'], array(E_ERROR, E_USER_ERROR))){ | |
echo '<h1>An error has occured. Team has been notified of the error</h1>'; | |
$to = 'example@email.com'; | |
$subject = "{$_SERVER['SERVER_NAME']} Fatal error in {$error['file']} on {$error['line']}"; | |
$message = var_export($error, TRUE) . PHP_EOL; | |
$message .= var_export($_SERVER, TRUE) . PHP_EOL; | |
//mail($to, $subject, $message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment