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

后端 未结 8 1465
太阳男子
太阳男子 2020-12-04 04:48

XDebug offers the configuration directive \"xdebug.profiler_enable_trigger\" that allows to activate profiling by passing the GET or POST parameter \"XDEBUG_PROFILE\" when c

相关标签:
8条回答
  • 2020-12-04 05:25

    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.

    0 讨论(0)
  • 2020-12-04 05:28

    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).

    0 讨论(0)
  • 2020-12-04 05:39

    Documentation from Jetbrains

    To start the script with debugging using PHP command line switches Set an environment variable that would tell XDebug to connect to IDE:

    Windows / MacOS / Linux

    export XDEBUG_CONFIG="idekey=123"  
    

    Here idekey should have a random value.

    Launch PHP with the following command-line options:

    php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_connect_back=0 path/to/script.php
    

    You may use 10.0.2.2 instead of 127.0.0.1 with Vagrant (see related SO question).

    0 讨论(0)
  • 2020-12-04 05:43

    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

    0 讨论(0)
  • 2020-12-04 05:44

    I created a shell script to handle client debugging.

    script name: phpdebug

    #!/usr/bin/ksh
    php -dxdebug.remote_host=`echo $SSH_CLIENT | cut -d "=" -f 2 | awk '{print $1}'` $*
    

    I placed this script in /usr/bin and gave it execute permissions.

    The script takes the arguments passed into phpdebug and calls php with the xdebug arguments and appends the arguments passed into the shell script, the $* on the end.

    0 讨论(0)
  • 2020-12-04 05:47

    In PhpStorm 7 using WAMP I got this to work by copying my already working xdebug settings from C:\wamp\bin\apache\apache2.2.22\bin\php.ini to the xdebug section of C:\wamp\bin\php\phpX.Y.Z\php.ini. Then I ran my script like so:

    php -d xdebug.idekey=PHPSTORM script.php
    

    This even worked for debugging laravel artisan scripts

    php -d xdebug.idekey=PHPSTORM artisan db:seed --force
    
    0 讨论(0)
提交回复
热议问题