How can I debug a PHP CLI script with xdebug?

眉间皱痕 提交于 2019-11-29 22:22:18
Pascal MARTIN

There is a couple of notes about that in Xdebug's manual, like, for instance (quoting) :

export XDEBUG_CONFIG="idekey=session_name"
php myscript.php

If you are using Eclipse PDT to develop and debug your PHP scripts, there is not much difference between Apache or CLI : the configuration lloks quite the same, you just don't have to configure a web server, nor indicate an URL ; instead, you have to indicate the path to the PHP executable.

About the XDEBUG_SESSION_START variable : well, you launch the whole script in "debug-mode", so you don't have any notion of "debugging-session", I'd say.


For instance, here's what Window > Preference > PHP > PHP executables looks like for me right now, and, on the right, what I get when clicking on the Edit button of the first one :


(source: pascal-martin.fr)
   


(source: pascal-martin.fr)

And the debug configurations window :


(source: pascal-martin.fr)

And launching the debugging: it just works :


(source: pascal-martin.fr)


Hope this helps :-)

Else, what specific problem do you encounter ?

If you're using bash (or similar shell), this little script might come in handy:

alias drush-debug=drd
function drd {
    export XDEBUG_CONFIG="idekey=cli_session"
    export SERVER_NAME="developer.machine"
    export SERVER_PORT="9000"
    drush "$@"
    unset XDEBUG_CONFIG
    unset SERVER_NAME
    unset SERVER_PORT
};

or as suggested by the commentators below

alias drd='XDEBUG_CONFIG="idekey=PHPSTORM" drush "$@"'

This way you don't have to manually set and unset the trigger variable each time you want to debug.

simply put the following section to your php.ini

[XDebug]
xdebug.max_nesting_level = 200
xdebug.remote_enable=1
xdebug.remote_port=9000
;xdebug.profiler_enable=1
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=1

and replace PHPSTORM with your ide key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!