For a long time I have been waiting for a PHP debugger that works. Until now, that was only ever half the case.
- Eclipse required me to set up overly complicated debug profiles
- NetBeans was also going into that direction
- MacGDBp always triggered and allowed to step through the code, but variable inspection is broken
PhpStorm had it's share of trouble as well, but yesterday I experienced a working debug session. Just like that, deep variable inspection and stepping through the code just worked. Today I looked into CLI debugging because Robert needed that for some complicated FLOW3 task. Also works, although it requires one step that should not be needed. Anyway, here we go.
Debugging through the browser
In PhpStorm you need to configure nothing, really. For the sake of it, have a look at the settings in "PHP > Debug". Here are mine:
So far I have no setup in "PHP > Servers" and nothing in "PHP > Debug > Skipped paths". Also, no run configurations are set up so far, just make sure the IDE key is set up:
Then, install the PhpStorm debugging bookmarklets (or some other Xdebug trigger), tell PhpStorm to listen for incoming connections (click the red telephone button so it turns into a green telephone button) and start a debug session using the IDE key you gave to PhpStorm as well. If all is well, a window should pop up:
Simply click Debug and off you go.
Debugging CLI scripts
For CLI scripts this "zero config" setup does not work (it does for MacGDBp, so, please fix it), thus you need to do some extra work. Create a server configuration in the settings:
And a debug configuration through "Run > Edit configurations":
Now start the debug session manually in PhpStorm ("Run > Debug...") and select the "Unnamed" debug configuration. PhpStorm should then open the debug panel and tell you it is waiting for an incoming connection. Now call your CLI script:
Now PhpStorm should pick up your debug request and stop at the first line or breakpoint.
- If you happen to have code in an excluded directory, e.g. for autogenerated things, you can step through them, but will do so blindfold, as PhpStorm does not ignore those files.
- Explore the options for watches and breakpoints, like conditions. Some powerful stuff is hidden there...
I hope this post helps you with debugging, feel free to leave comments with further tips and (hopefully) success stories.