Home  >  Q&A  >  body text

Register_shutdown_function error handling cannot print logs

<?php
error_reporting(0);
register_shutdown_function('customSeriousError');

function customSeriousError()
{
    if ($err = error_get_last()) {
        file_put_contents('log.txt', '1231313', FILE_APPEND);
        // 可以退出,打印错误,但是没有输出日志
        exit(json_encode(array('code' => 500, 'message' => "error: [{$err['type']}] {$err['message']}  in  {$err['file']}  on  {$err['line']}")));
    }
}
class UTIL
{
    public static function returnMember($arg, $default=0)
    {
        var_dump($arg);
        var_dump($default);
        return $arg;
    }
}
UTIL::returnMember();
?>
陈健陈健2028 days ago658

reply all(2)I'll reply

  • 陈健

    陈健2018-12-28 10:47:12

    The PHP file is placed under the virtual host configured by Apache, but the log.txt entered in the file is still in the root directory of Apache, so there is no response to the log.txt in the virtual host directory

    reply
    0
  • Cancelreply