gpt4 book ai didi

php - XDebug 断点在 Visual Studio Code 中给出 PHP 错误

转载 作者:行者123 更新时间:2023-12-04 11:04:07 24 4
gpt4 key购买 nike

我正在尝试使用 XDebug 和 Visual Studio Code 在 PHP 代码中设置断点,这些代码都安装在 Ubuntu Hyper-V 虚拟机上。我使用的是 PHP 7.2。

每当我在 PHP 代码中设置断点并刷新应该命中断点的页面时,我都会收到错误“命令不可用”和“没有这样的断点”显示在 Visual Studio 代码的弹出窗口中。我还在调试控制台中收到以下错误。

XDebugError: command is not available
at new Response (/home/ben/.vscode/extensions/felixfbecker.php-debug-
1.13.0/out/xdebugConnection.js:56:19)
at new BreakpointSetResponse (/home/ben/.vscode/extensions/felixfbecker.php-debug-
1.13.0/out/xdebugConnection.js:207:9)
at Connection.<anonymous> (/home/ben/.vscode/extensions/felixfbecker.php-debug
1.13.0/out/xdebugConnection.js:599:20)
at Generator.next (<anonymous>)
at fulfilled (/home/ben/.vscode/extensions/felixfbecker.php-debug-1.13.0/out/xdebugConnection.js:4:58) {
code: 5,
name: 'XDebugError'
}

根据我的研究,我认为问题在于 XDebug 不适用于 IPv6,但调试器正在监听 v6。如果我这样做 netstat -an | grep 9000 ,我得到
tcp6       0      0 :::9000                 :::*                    LISTEN  

以下是 /etc/php/7.2/fpm/conf.d/20-xdebug.ini的内容
zend_extension=xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_mode=req
xdebug.remote_port=9000
xdebug.var_display_max_depth=-1
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1

我如何解决这个问题并使我的断点工作?

最佳答案

我使用这些扩展进行调试:

  • PHP 调试(作者:Robert Lu)
  • PHP Intelephense (by Ben Mewburn)

  • 请检查您的项目的 XDebug 配置。这是一个 launch.json .vscode 您项目根目录中的文件夹。如果缺少,则必须在 Visual Studio Code 的调试设置中创建(齿轮按钮)。
    它应该是这样的:
    {
    // 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}"
    }
    ]
    }

    关于php - XDebug 断点在 Visual Studio Code 中给出 PHP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61143648/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com