How can I debug a PHP CLI script with xdebug?

后端 未结 4 593
太阳男子
太阳男子 2020-12-13 02:47

I haven\'t quite figured this out. EVERY piece of documentation I\'ve found covers how to use xdebug to debug scripts running in Apache. I need to debug a php CLI script.

4条回答
  •  我在风中等你
    2020-12-13 03:10

    For Windows and Visual Studio Code here's how to proceed:

    1. Download xdebug from https://xdebug.org/download. For example php 7.4 Windows 64bit https://xdebug.org/files/php_xdebug-2.9.5-7.4-vc15-nts-x86_64.dll

    2. Copy the xdebug dll to your php extensions dir (ext).

    3. Add to the end of php.ini

        [XDebug]
        zend_extension=php_xdebug-2.9.5-7.4-vc15-nts-x86_64.dll
    
        xdebug.remote_enable=1
        xdebug.remote_autostart=1
    
    1. Open VSCode and install https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug

    2. Open the project workspace in VSCode, go to Run tab, click the cogwheel and add these lines

        {
          "name": "listen CLI",
          "type": "php",
          "request": "launch",
          "port": 9000
        },
        {
          "name": "run CLI",
          "type": "php",
          "request": "launch",
          "program": "${file}",
          "cwd": "${fileDirname}",
          "port": 9000
        }
    
    1. Place a break point in the script you want to debug

    2. Select "run CLI" and click "Start Debugging"

    Happy debugging!

提交回复
热议问题