Visual Studio Code - Xdebug won't work

时光怂恿深爱的人放手 提交于 2019-12-08 00:34:55

问题


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

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);
?>

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

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

my launch.json file looks like this:

{
"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?

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

回答1:


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.



来源:https://stackoverflow.com/questions/42368503/visual-studio-code-xdebug-wont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!