首页 文章

Visual Studio代码 - Xdebug不起作用

提问于
浏览
1

在Visual Studio Code(1.9.1)(mac)中,我已经设置了php-debug插件 .

在调试屏幕中,我开始'听Xdebug' .
在此之后,我在我的XAMPP服务器(本地)上打开index.php .
但没有任何反应 .

  • 屏幕底部的蓝色条变为橙色 .

  • 步骤结束,步入和退出按钮显示为灰色 .

  • 此外,监视变量发生以下错误消息:
    cannot evaluate code without an connection

我尝试在以下代码上使用断点:

<?php
$i = 0;

do {
$i++;
if (!($i % 1)) {
    echo('<p>$i = ' . $i . '</p>');
    }
}
while ($i < 100);
?>

我正在使用XAMPP,在我的 php.ini 文件中,我使用端口9000进行Xdebug .

zend_extension="/usr/local/Cellar/php71-xdebug/2.5.0/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote.port=9000

我用自制软件安装了Xdebug .
这是我的php信息:phpinfo.htm
Xdebug wizard告诉我Xdebug已正确安装 .

我的 launch.json 文件如下所示:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "log": true
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]
}

谁会知道我做错了什么?

在ini文件中设置 xdebug.remote_connect_back = 1 之后
因为n00dl3建议调试大部分时间都有效,但偶尔我会得到以下内容
调试控制台中的错误:

<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'exited', threadId: 1 } }

1 回答

  • 1

    似乎需要在launch.json中使用 localSourceRoot 设置服务器根,如下所示:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Listen for XDebug",
                "type": "php",
                "request": "launch",
                "port": 9000,
                "log": true,
                "localSourceRoot": "http://127.0.0.1/public_html/"
            },
            {
                "name": "Launch currently open script",
                "type": "php",
                "request": "launch",
                "program": "${file}",
                "cwd": "${fileDirname}",
                "port": 9000
            }
        ]
    }
    

    现在断点正如他们应该的那样工作 .

相关问题