Created
May 26, 2015 07:35
-
-
Save lillesvin/c2a48f19a2a6df4dc9a0 to your computer and use it in GitHub Desktop.
Handler for logging last error even when fatal
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
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