debug_backtrace() from registered shutdown function in PHP

前端 未结 5 503
长发绾君心
长发绾君心 2020-12-15 05:02

While tinkering for an answer to this question, I found that debug_backtrace() doesn\'t trace beyond the function registered to register_shutdown_function

5条回答
  •  [愿得一人]
    2020-12-15 05:33

    This is a very expensive solution. I never used register_tick_function() or tick and I'm not sure if it works as expected.

    declare(ticks=1);
    
    function tick_handler() {
        global $backtrace;
        $backtrace = debug_backtrace();
    }
    register_tick_function('tick_handler');
    
    
    
    function shutdown() {
        global $backtrace;
        // do check if $backtrace contains a fatal error...
        var_dump($backtrace);
    }
    register_shutdown_function('shutdown');
    

提交回复
热议问题