Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

visual studio code - Any examples of PHP Debug configurations in VSCode?

I have installed PHP Debug plugin in VSCode, unfortunately, it didn't give me any automation on creating launch configurations. For example, Add Configuration doesn't give me PHP option

enter image description here

(there is no PHP option anywhere below)

In documentation in section VS Code Configuration it is said sample configurations appear on Gear icon click, but this doesn't work for me (nothing happens on gear click).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Default entries for PHP debug (no launch.json file was present before that).

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

Created them using this way:

enter image description here

You can run through questions where both & tags are present to see other possible configs (but usually that would be just default entries).


P.S. I had to add the following bit for Xdebug to actually try to debug (for "Launch currently open script" entry .. which runs the script in CLI environment). Without it it was just executing it (PhpStorm IDE is better in this regard as it automatically adds such bit when "Debug" button is used).

The IDE key can be anything, it just that this environment variable to be present (at very least here in my setup on Windows 10).

            "env": {
                "XDEBUG_CONFIG": "idekey=VSCODE"
            },

this also works for me:

            "env": {
                "XDEBUG_CONFIG": ""
            },

I've also tried "XDEBUG_SESSION": "1" .. but it did not worked for me.

Without that (or when you cannot override it as you already have such environment variable with your own stuff) you may need to have xdebug.start_with_request = yes in your php.ini (which tells Xdebug to try to debug every single script -- it's inconvenient to have it there as it will be applied to ALL PHP scripts that are run with that php.ini) .. or have xdebug_break(); in your PHP code.


Yet another way is to configure "program": "${file}" line and specify PHP interpreter there as well as any Xdebug config (which also is not super convenient but is more flexible is certain scenarious, e.g. when you have multiple PHP on your system and have to run this script with non-default one), for example:

"program": "/path/to/php -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 -dxdebug.start_with_request=yes ${file}"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...