捕获错误并发邮件 register_shutdown_function

/**
 *  脚本程序异常捕获
 */
function handleError()
{
    global  $config;
    $error = error_get_last();
    if (isset($error['type'])) {
        switch ($error['type']) {
            case E_ERROR :
            case E_PARSE :
            case E_DEPRECATED:
            case E_CORE_ERROR :
            case E_COMPILE_ERROR :
                $file = $error['file'];
                $line = $error['line'];
                $log = "{$error['message']} ({$file}:{$line})
";
                error_log($log);
                // 发报警邮件
                sendMail($config['alarm_email'] , '异常报警!', $log);
        }
    }
}

//捕获脚本错误

register_shutdown_function('handleError');

  

原文地址:https://www.cnblogs.com/jamesbd/p/4789354.html