【问题标题】:Debug php using VS Code: Unable to attach to browser使用 VS Code 调试 php:无法附加到浏览器
【发布时间】:2020-08-25 23:41:20
【问题描述】:

我已按照此处的说明安装了 xdebug:http://xdebug.org/wizard

我还安装了 Debugger for Chrome 扩展

现在我选择我的 index.php 文件并启动调试器,但我收到以下错误:

这是lunch.json的内容

这是我添加到 php.ini 中的配置

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
zend_extension = /usr/lib/php/20170718/xdebug.so

更新:

我已将xdebug.remote_log=/tmp/xdebug.log 添加到 php.ini,这是我得到的错误:

[3569] I: Connecting to configured address/port: localhost:9000.
[3569] W: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
[3569] E: Could not connect to client. :-(

【问题讨论】:

  • 设置xdebug.remote_log=/tmp/xdebug.log 看看它会显示什么。
  • @Derick:感谢您的帮助,我已经添加了日志消息。
  • 你的日志显示 VS Code 没有监听。你需要像这样配置它:codewall.co.uk/debug-php-in-vscode-with-xdebug

标签: php visual-studio-code ubuntu-18.04 xdebug


【解决方案1】:

我关注了@Derick 在评论中提供的this document。我将 lunch.json 更改为以下内容并开始工作:

{
    // 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,
            "runtimeExecutable": "/usr/bin/php.exe"
        }
    ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    • 2021-04-17
    • 2018-09-09
    • 2018-01-17
    • 1970-01-01
    • 2014-02-04
    相关资源
    最近更新 更多