register_shutdown_function()不会调用我的函数

时间:2014-02-18 18:54:04

标签: php error-handling

当脚本出现致命错误时,我已经制作了自定义重定向功能:

在所有页面之前包含的前置脚本中调用它:

register_shutdown_function("shutdownHandler");
function shutdownHandler() 
{
    $lasterror = error_get_last();
    switch ($lasterror['type'])
        {
            case E_ERROR:
            case E_CORE_ERROR:
            case E_COMPILE_ERROR:
            case E_USER_ERROR:
            case E_RECOVERABLE_ERROR:
            case E_CORE_WARNING:
            case E_COMPILE_WARNING:
            case E_PARSE:
                $error = "[SHUTDOWN] lvl:" . $lasterror['type'] . " | msg:" . $lasterror['message'] . " | file:" . $lasterror['file'] . " | ln:" . $lasterror['line'];
                writeError($error, "fatal");
                header("location:maintenance.php");
        }
}

但是没有调用函数,任何想法?

2 个答案:

答案 0 :(得分:0)

我解决了这个问题!

通过我的php.ini文件在指令下添加我的errorsHandler.php脚本:

auto-prepend-file = [path / to / file]

希望它会有所帮助;)

答案 1 :(得分:0)

您还可以禁用PHP以显示错误,这可能导致您的shutdownHandler函数无法被调用。

您可以在php.ini文件或PHP文件中执行此操作:

ini_set('display_errors', false);