Skip to content

Instantly share code, notes, and snippets.

@olimortimer
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olimortimer/aade89e7e263f22069f5 to your computer and use it in GitHub Desktop.
Save olimortimer/aade89e7e263f22069f5 to your computer and use it in GitHub Desktop.
PHP: Catch script failure
<?php
// Multiple ways of registering a function for execution on shutdown
// Class method
public function __construct() {
register_shutdown_function(array($this, 'scriptFailure'));
}
// Non-class method
register_shutdown_function('scriptFailure');
// Anonymous function
register_shutdown_function(function() {
if($error = error_get_last()) mail('developer@email.com', 'Script Failure', print_r($error, true));
});
// Function to catch and email the error
private function scriptFailure() {
if($error = error_get_last()) mail('developer@email.com', 'Script Failure', print_r($error, true));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment