Visual Studio代码-Xdebug无法正常工作 [英] Visual Studio Code - Xdebug won't work

查看:489
本文介绍了Visual Studio代码-Xdebug无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio代码(1.9.1)(mac)中,我设置了 php-debug 插件.

In Visual Studio Code (1.9.1) (mac) i have setup the php-debug plugin.

在调试屏幕中,我开始"收听Xdebug ".
之后,我在XAMPP服务器(本地)上打开index.php.
但是什么也没发生.

In the debug screen i start 'listen for Xdebug'.
After this i open the index.php on my XAMPP server (local).
But nothing happens.

  • 屏幕底部的蓝色条变为橙色.
  • 跨步",步入"和步出"按钮显示为灰色.
  • 在监视的变量上还会出现以下错误消息:
    没有连接就无法评估代码
  • the blue bar at the bottom of the screen turns orange.
  • the step over, step into and step out buttons are greyed out.
  • Also the following error message occurs at the watched variables:
    cannot evaluate code without an connection

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

I try to use breakpoints on the following code:

<?php
$i = 0;

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

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

I am using XAMPP and in my php.ini file i use port 9000 for 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向导告诉我Xdebug已正确安装.

I installed Xdebug using homebrew.
Here is my php info: phpinfo.htm
Xdebug wizard tells me Xdebug is installed correctly.

我的 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
    }
]
}

有人会知道我在做什么错吗?

Would anyone know what i am doing wrong?

在ini文件中设置xdebug.remote_connect_back = 1
由于n00dl3建议大多数时间进行调试,但是偶尔我会得到以下内容
调试控制台中出现错误:

After setting the xdebug.remote_connect_back = 1 in the ini file
as n00dl3 suggested debugging most of the time works, but once in a while i get the following
error in the debug console:

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

推荐答案

似乎需要设置服务器根目录 在带有 localSourceRoot 的launch.json中,如下所示:

It seemed the server root needed to be set in the launch.json with localSourceRoot like this:

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

现在断点正在按应有的方式工作.

Now breakpoints are working like they should.

这篇关于Visual Studio代码-Xdebug无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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