Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php register\u shutdown\u function()不调用我的函数_Php_Error Handling - Fatal编程技术网

Php register\u shutdown\u function()不调用我的函数

Php register\u shutdown\u function()不调用我的函数,php,error-handling,Php,Error Handling,嗨,当脚本上出现致命错误时,我创建了一个自定义重定向功能: 在包含在所有页面之前的前置脚本上调用: register_shutdown_function("shutdownHandler"); function shutdownHandler() { $lasterror = error_get_last(); switch ($lasterror['type']) { case E_ERROR: case E_C

嗨,当脚本上出现致命错误时,我创建了一个自定义重定向功能:

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

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");
        }
}
但是函数没有被调用,有什么想法吗?

我解决了这个问题

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

自动前置文件=[path/to/file]


希望有帮助

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

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

ini_set('display_errors', false);

请给出一个完整的示例,包括如何注册该函数。shutdownHandler在哪里执行?在所有脚本之前包含的脚本中执行