You can register a shutdown function that gets called even in the case of a
fatal error. We use something like this:

    public function init() {
        register_shutdown_function(array('Bootstrap', 'fatalErrorCatcher'));

    public function fatalErrorCatcher() {
        $error = error_get_last();
        if( $error && (
                $error['type'] === E_ERROR ||
                $error['type'] === E_COMPILE_ERROR ||
                $error['type'] === E_CORE_ERROR ||
                $error['type'] === E_PARSE
            )) {
            // kill the buffer content, it's broken anyway
            while(ob_get_level()) {
            // log error to a file
            // issue 500 and dump out a static "site is broken oh noes!"
            header('HTTP/1.1 500 Internal Server Error');
            echo file_get_contents('fail-whale.html');

In catchFatalError() we check the last error to see if it's truly fatal. Our
general error-handler has already handled all other error types, and this
since function gets called no matter how the PHP process shutsdown, you
don't want to issue a 500 for a successful request. :)


Reply via email to