1

I'm trying to run a CLI script in PhpStorm and use the debugger to step through it.

It took some doing, but I now have Xdebug installed and the PhpStorm CLI Interpreters dialog confirms that:

enter image description here

I created a Run/Debug config and when I try to execute/debug it, the script runs all the way through without breaking at my breakpoints and I get this error at the bottom of PhpStorm:

enter image description here

The PhpStorm docs say that xdebug for CLI scripts can configured with an environment variable like this:

export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"

I've confirmed that PhpStorm sees that environment variable:

enter image description here

Here is my Run/Debug config:

enter image description here

I'm at a complete loss here. How can I get this thing to debug a CLI PHP script?

3
  • 1) "...cannot establish connection to xdebug 2.6.0" It's Xdebug that connects to PhpStorm and NOT other way around. 2) You are on Mac and using default 9000 port for Xdebug. Thing is -- you may have php-fpm running on your Mac... and by default it also uses that port... and PhpStorm on Mac cannot detect that Xdebug port is already in use. You can check what app is listening to TCP 9000 with sudo lsof -nP -iTCP -sTCP:LISTEN. Suggested resolution is to change Xdebug port to 9001 in both php.ini and PhpStorm settings. Commented Jul 31, 2018 at 18:14
  • 3) "The PhpStorm docs say that xdebug for CLI scripts can configured with an environment variable like this:" If you executing Debug from PhpStorm ... it will pass all needed parameters to PHP executable together with the path to the script. Such config may only be needed if you launch script from outside of IDE and PhpStorm just listens for incoming connections. Commented Jul 31, 2018 at 18:17
  • @LazyOne Thank you for your help, but it turned out that it was something completely unrelated to debugging. Blerg. Commented Jul 31, 2018 at 18:39

1 Answer 1

2

Gah, I hate it when I spend a couple of hours trying to fix something and discover it's totally unrelated.

The problem was that I'm using short tags and my cli php.ini file had short_open_tag=Off. The code I'm running is normally run in a web context and the php.ini for that web context had short_open_tag=On so the code was working.

This code is an api endpoint and I needed to be able to step through and see what was going on and there's nothing that inherently requires it to run in the web context (except for the input params, but I'm faking those for testing purposes anyway).

So, my debug configuration was fine.

I discovered it by trying to reduce the problem further and further and I just tried running the code directly from a command line (php sync.php) to see that it was at least working and producing the correct output.

It wasn't producing the normal api json output, it was just echoing all of the code in the file. That's what led me down the path to realizing my stupid mistake.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.