Fastest way to determine where PHP script exits

前端 未结 9 2302
故里飘歌
故里飘歌 2020-12-14 21:02

Say you have a large PHP project and suddenly, when attempting to run it, you just end up with a blank page. The script terminates and you want to find exactly where that is

相关标签:
9条回答
  • 2020-12-14 21:42

    Don't forget to grep for "exit" too.

    0 讨论(0)
  • 2020-12-14 21:44

    With some inspiration from the nonworking but still right-direction answer from RoBorg, I used the following code in the beginning:

    function shutdown() {
        global $dbg_stack_a;
        print_r($dbg_stack_a);
    }
    register_shutdown_function('shutdown');
    

    And then I made a global conditional breakpoint (global = breakpoint is evaluated on each row), exploiting the fact that it can run code trough eval(), with the following "condition":

    eval('
    global $dbg_stack_a, $dbg_stack_b, $dbg_stack_c;
    $dbg_stack_a = $dbg_stack_b;
    $dbg_stack_b = $dbg_stack_c;
    $dbg_stack_c = debug_backtrace();
    return false;
    ')
    

    Probably not fast but does the trick! Using this I was able to determine the exact file and line location that raised die(). (This example works in NuSphere.)

    0 讨论(0)
  • 2020-12-14 21:44

    Add this to the top of the file:

    function shutdown()
    {
        print_r(debug_backtrace());
    }
    
    
    register_shutdown_function('shutdown');
    

    See register_ shutdown_function()

    0 讨论(0)
  • 2020-12-14 21:45
    grep -n die filename
    
    0 讨论(0)
  • You can use an interactive debugger to step through the code until you reach the exit point. Other than that, I think you're down to grep'ing the code for exit|die.

    0 讨论(0)
  • 2020-12-14 21:52

    Also check the error___logs for "memory_limit" errors in the Apache error_log.

    Memory Limit >= 10M Warning: (Set this to 10M or larger in your php.ini file)

    In my experience, scripts suddenly end without warning or notice when this happens.

    0 讨论(0)
提交回复
热议问题