如何记录PHP是否达到执行超时?

如何记录PHP是否达到执行超时?,php,Php,当PHP超过max\u execution\u time且执行终止时,如何记录日志 我已经有了这两个功能 register_shutdown_function(function(){ if($error = error_get_last()){ switch($error['type']){ case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR:

当PHP超过
max\u execution\u time
且执行终止时,如何记录日志

我已经有了这两个功能

register_shutdown_function(function(){
    if($error = error_get_last()){
        switch($error['type']){
            case E_ERROR:
            case E_CORE_ERROR:
            case E_COMPILE_ERROR:
                $message = $error['message'].' '.$error['file'].'('.$error['line'].')';
                if(class_exists('Log')){
                    Log::write($message, 'fatal', true, true);
                }
                if(ENV != ENV_PROD){
                    echo $message;
                }
                break;
        }
    }
});

set_error_handler(function(int $errno, string $errstr, string $errfile, int $errline){
    switch($errno){
        case E_WARNING:
        case E_PARSE:
        case E_NOTICE:
            $message = "$errstr $errfile($errline)\n".(new Error)->getTraceAsString();
            if(class_exists('Log')){
                Log::write($message, 'warning', true, true);
            }
            if(ENV != ENV_PROD){
                echo $message;
            }
            break;
    }
});

这不可能直接实现,因为根据定义,脚本在终止时无法执行任何日志记录。您可以使用日志文件分析器尝试解释请求的http状态代码,或者您必须实现定期记录的life beat。可能有用;此外,php错误日志还应显示超出了执行时间。@Spechal OP说他们已经尝试了register\u shutdown\u函数。我很想把这个问题标记为重复的问题。可能是重复的