I was just asked how to debug PHP, using Zend Studio, but for a CLI PHP script, as opposed to a normal web-based PHP script. (Web based debugging is easy – fire up Zend Studio, load up Firefox with the Zend Toolbar installed, and hit "Debug".)
To be honest, debugging your CLI PHP scripts is almost as easy! All you need to do is launch your PHP script from a simple bash script, that does a little bit of simple magic for you:
#!/bin/sh export QUERY_STRING="start_debug=1&debug_port=10000&debug_host=IP&debug_stop=1" /path/to/php -q /path/to/script.php
Just replace IP with your IP address (be it 127.0.0.1, or whatever), launch Zend, and start debugging. Easy!
UPDATE: Zend have similar info on their site these days…
Taking this one step further, I created a bash script “debug”, placed it in $PATH, and put the following in it:
#!/bin/sh
export QUERY_STRING=”start_debug=1&debug_port=10000&debug_host=127.0.0.1&debug_stop=1″
/usr/bin/php -q $@
Now I can just do “debug script.php variable1 variable2 variable3 …”
Just for completeness, I thought I’d mention that it’s normally a good idea to surround $@ with double-quotes, to pass parameters with spaces in them.