简体   繁体   中英

Debugging a PHP Command line Program

I have set up PHP Storm with Xdebug and I am trying to debug a console program

the program runs ok, but if I try and debug it to see whats going on under the hood the debugging stops when it gets to teh part where the user inputs data.

$line = fgets ($GLOBALS['StdinPointer'],$length);

Debugging just stops, no error message or anything.

Whereas when I run the program normally it waits for information from user and continues as expected

Given the following function:

    function read ($length='255')
    {
        if (!isset ($GLOBALS['StdinPointer']))
        {
            $GLOBALS['StdinPointer'] = fopen ("php://stdin","r");
        }
        $line = fgets ($GLOBALS['StdinPointer'],$length);
        return trim ($line);
    }

I set a break point on each line, I hit the 'Resume Program' Icon and the program goes to the next line, however when I get to the line with fgets function debugging just stops (all break points disappear, no way to enter input from command line)

Its as if it fails to stop at the fget function as it does when running normally

There is no record of the program crashing from logs

Your questions is missing some crucial information. You say: "Debugging just stops, no error message or anything.", but you ommit to mention whether it is waiting for user input. That is what it is supposed to do afterall.

If it is waiting then simply enter something and after $length of input the debugging will continue.

If it isn't waiting for user input, then you really have a problem. I cannot completely explain this situation other than saying that there must be some interaction between PHP waiting for input and the debugger waiting for input.

I think it is more likely you just have to hit your keyboard for a while, and it will respond. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM