register_shutdown_function with error 500

901 Views Asked by At

I am trying to download some big videos from dropbox and then upload them again to another server. This works pretty well with small files. However when the files are getting bigger, I keep getting 500er errors. I was trying to catch them via register_shutdown_function (see How do I catch a PHP Fatal Error for more details) but apparently the handler gets never called (I dont get any emails whatsoever). Is there something I am doing wrong here?

// error handler
function fatal_handler() {
    $error = error_get_last();
    if( $error !== NULL) {
        $errno   = $error["type"];
        $errfile = $error["file"];
        $errline = $error["line"];
        $errstr  = $error["message"];
        error_mail(format_error( $errno, $errstr, $errfile, $errline));
    }
}

function format_error( $errno, $errstr, $errfile, $errline ) {
    $trace = print_r( debug_backtrace( false ), true );
    // some beautiful error output with content being the container
    return $content;
}

function error_mail($msg) {
    mail("[email protected]", "Error", $msg);
}

register_shutdown_function('fatal_handler');
error_reporting(E_ALL);
0

There are 0 best solutions below