Debugging CLI php script
Hello,
I've tried to find a way to debug a CLI php script I'm working on and the few solution I've found all require editing one or more .ini anc configurations files, that I don't want to edit, since it took me hours to make xDebug work on MAMP Pro (so, it's a Mac for these people that doesn't know it) and I don't want to lose this environment.
So, is it possible that debugging php should be such a pain?
What should I do to simply debug my CLI php scripts with xDebug, except praying (that does't work much)?
Thanks.
Please sign in to leave a comment.
Andrea,
ini settings are pretty straightforward for CLI debugging. Just make sure that they have
zend_extension="<full_path_to_xdebug_lib>"
xdebug.remote_enable=true
Please also be sure that CLI uses the same INI file that you're editing. Usually MAMP and CLI uses different php.ini.
Maxim,
Maybe I wasn't clear.
The issue is not on debugging in general: I can do this already with php script that runs in a local web server.
What I can't do is debugging a CLI php script.
What I've found so far, even here in the community, is confusing, unclear, undetailed or just non understandable.
I want to be able to debug both CLI and web php scripts and I don't want to change any .ini file each time I switch from a CLI to a Web script.
I understand the problem. It's possible to debug CLI script and web server script with the same INI. I'm just trying to figure out why your configuration doesn't work for CLI. Could you please copy paste output that you will get by going to Settings->PHP choosing desired interpreter and clicking "i" button?
Hi there,
Please describe what you mean by "CLI php script" .. because as far as I'm aware it's just a matter of using Run/Debug Configuration of different type in PhpStorm ("PHP Script" is for executing your php code in CLI environment).
Sure:
PHP version: 5.4.10
Loaded extensions:
bcmath, bz2, calendar, Core, ctype, curl, date, dom, ereg, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, imap, json, ldap, libxml, mbstring, mcrypt, mysql, mysqli, openssl, pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, Reflection, session, SimpleXML, soap, sockets, SPL, sqlite3, standard, tokenizer, XCache, xdebug, xml, xmlreader, xmlwriter, xsl, yaz, zip, zlib
Configuration options:
CLI php script is a php script I run from the command line (from PHPStorm, using the command line window).
When I enable the listener, and I set a breakpoint, nothing happens.
It's not the right way to run scripts from PhpStorm:) Open script in Editor->Right Click->Debug or you may create corresponding configuration.
Based on your phpinfo table: you clearly have xdebug.remote_enable = 0 (disabled) while it must be enabled.
http://confluence.jetbrains.com/display/PhpStorm/Xdebug+Installation+Guide
In such scenario you definitely need to edit your .php.ini (which is what you categorically do not want to do) .. or launch php interpreter/script with additional parameters (to enable those xdebug settings), which is inconvenient to do manually to say the least. "PHP Script" Run/Debug Configuration does it for you (extra parameters that tell xdebug that this script needs to be debugged).
In latest EAP build of PhpStorm v7, you can use built-in tool that will help you validating your debugger setup (php.ini): http://blog.jetbrains.com/phpstorm/2013/08/debugger-configuration-validation-with-phpstorm/
Well, that's strange, as I clearly debug php when running from a local site.
I have no idea why it says that is not enabled. I fI open the php.in, this is the [xdebug] section:
[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
xdebug.default_enable=1
xdebug.coverage_enable=1
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/tmp"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
Most likely you do have 2 php.ini files (they may have different names, not necessary php.ini): one for Web interface and one for CLI (you should know this already: http://devnet.jetbrains.com/message/5487515#5487515 ).
This phpinfo you showed here was taking by clicking on a button in PhpStorm (which will run PHP in CLI mode, obviously). Unfortunately it does not show ALL details, only the important settings. Instead -- write simple script that calls phpinfo() and execute it in command line / terminal -- there check what config file was used (top of the output) and see if you have edited the correct php.ini file.
Well, this is driving me crazy.
The thread you've linked helped me somehow to debug php scripts that are ran from a web server.
I never managed to debug clicking on the "play" button, but only to enable the listener.
After all this was for the best, as I can enable/disabel the debugger as I wish.
However, this doesn't seem to help with the CLI script.
For your information, I've checked on PhpStorm settings and the only php interpteter that is configured is the 5.4.
However, the command line still gives me the 5.3.15 version.
The EAP doesn't help much, as validating only shows the message "Failed to execute validation script", that is not much helpful: which scripts? Which errors did get the validation?
If I build a validation logic, I would at least try to give some more detailed information, instead of such a generic message.