Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Handler for logging last error even when fatal
class ShutdownHandler
{
private $catch;
private $error;
public function __construct($catch = null)
{
$this->catch = $catch ?: E_ERROR | E_PARSE;
}
private function getError()
{
$this->error = error_get_last();
}
private function isPanicWorthy()
{
if (!is_null($this->error)) {
return $this->error['type'] & $this->catch;
}
return false;
}
public function panic()
{
$this->getError();
if ($this->isPanicWorthy()) {
/**
* Send error metrics to Librato, New Relic,
* via email or whatever.
*/
}
}
}
register_shutdown_function([new ShutdownHandler(), 'panic']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.