Skip to content

Instantly share code, notes, and snippets.

@ravinsharma12345
Last active December 21, 2015 00:09
Show Gist options
  • Save ravinsharma12345/6218249 to your computer and use it in GitHub Desktop.
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.
<?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