Thursday, March 03, 2016

Enabling xdebug on the command line

Just a quick note to my future forgetful self, and other Mac and PhpStorm users:

To enable PHP xdebug to debug command line scripts, the simplest way is to enable the extension and setup the parameters when you invoke PHP on the command line. Doing that can be a bit verbose, so to do this nicely, setup an alias in .bash_profile or .bashrc  or .zhrc, like so:

Just make sure xdebug is installed, you're enabling the correct extension for your version of PHP, the remote_host is set to the IP of the machine you're running the script on, and that your listener (PhpStorm in my case) is listening to the same remote_port.

After you've set that up, if you want to see what other options you can enable, just run:
"phpx -i | grep xdebug"

Running xdebug-enabled PHP this way has the nice side-effect of only enabling xdebug when you need it, avoiding its effect on performance when you don't.

Of course your mileage on Windows may vary.

No comments: