VSCode 中 PHP 调试配置的任何示例? [英] Any examples of PHP Debug configurations in VSCode?

查看:22
本文介绍了VSCode 中 PHP 调试配置的任何示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了

(下面没有 PHP 选项)

您可以运行以下问题,其中 & 存在标签以查看其他可能的配置(但通常这只是默认条目).


P.S. 我必须为 Xdebug 添加以下位才能实际尝试调试(对于启动当前打开的脚本"条目 .. 在 CLI 环境中运行脚本).没有它,它只是执行它(PhpStorm IDE 在这方面更好,因为它会在使用调试"按钮时自动添加这样的位).

IDE 密钥可以是任何东西,只要这个环境变量存在(至少在我在 Windows 10 上的设置中).

 环境":{XDEBUG_CONFIG":idekey=VSCODE"},

这也适用于我:

 环境":{XDEBUG_CONFIG":"},

我也试过 "XDEBUG_SESSION":"1" .. 但它对我没有用.

没有那个(或者当你不能覆盖它,因为你已经有这样的环境变量和你自己的东西)你可能需要在你的 php.ini 中有 xdebug.start_with_request = yes (它告诉 Xdebug尝试调试每个脚本——将它放在那里很不方便,因为它将应用于所有使用该 php.ini 运行的 PHP 脚本) .. 或具有 xdebug_break(); 在您的 PHP 代码中.


另一种方法是配置 "program":"${file}" 行并在那里指定 PHP 解释器以及任何 Xdebug 配置(这也不是超级方便,但是更灵活的是某些场景,例如,当您的系统上有多个 PHP 并且必须使用非默认脚本运行此脚本时),例如:

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

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

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

解决方案

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:

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}"

这篇关于VSCode 中 PHP 调试配置的任何示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆