How to trigger XDebug profiler for a command line PHP script?

You can pass INI settings with the -d flag: php -d xdebug.profiler_enable=On script.php.


with PhpStorm on remote webserver i use this command:

XDEBUG_CONFIG="idekey=PHPSTORM" PHP_IDE_CONFIG="serverName=server_name" php -dxdebug.remote_host=`echo $SSH_CLIENT | cut -d "=" -f 2 | awk '{print $1}'` myscript.php

where server_name stands for name of the server in PhpStorm project conifuguration


I got this working on Ubuntu/Netbeans by:

  • copying the xdebug config lines from the /etc/php5/apache2/php.ini file into /etc/php5/cli/php.ini
  • setting an environment variable with the name of the debug session (you can get this from the query string in the url of the page netbeans launches when you start debugging) the command is: export XDEBUG_CONFIG="idekey=netbeans-xdebug"

Then it's simply a case of starting debugging in netbeans and doing "php myscript.php" at the command line.


As described on the Xdebug Remote Debugging page, profiling can also be enabled via the XDEBUG_CONFIG environment variable by inluding a "profile_enable=1" directive:

XDEBUG_CONFIG="profiler_enable=1" php ...

For ease of use, the above command line can be written as an alias:

alias xphp='XDEBUG_CONFIG="profiler_enable=1" php'

The alias can be added to one of your shell's (interactive) startup scripts, such as ~/.bash_aliases or ~/.bashrc (as appropriate to your system).