register_shutdown_function,错误500

时间:2015-06-10 20:38:17

标签: php error-handling

我正在尝试从Dropbox下载一些大视频,然后再将它们上传到另一台服务器。这适用于小文件。但是当文件越来越大时,我总是会遇到500个错误。我试图通过register_shutdown_function捕获它们(有关详细信息,请参阅How do I catch a PHP Fatal Error)但显然处理程序从未被调用过(我没有收到任何电子邮件)。我在这里做错了吗?

// 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@example.org", "Error", $msg);
}

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

0 个答案:

没有答案