Handle fatal errors in PHP using register_shutdown_function()

后端 未结 4 1526
南旧
南旧 2020-11-27 14:49

According to the comment on this answer it is possible to catch Fatal Errors through a shutdown function which cannot be caught using set_error_handler().

4条回答
  •  攒了一身酷
    2020-11-27 15:11

    I use "ob_start" for this.

    function fatal_error_handler($buffer) {
        if (preg_match("|(Fatal error:)(.+)|", $buffer, $regs) ) {
            //Your code
        }
        return $buffer;
    }
    ob_start("fatal_error_handler");
    

提交回复
热议问题