首页 文章

VSCode / Xdebug PHP中没有显示变量

提问于
浏览
0

我正在尝试使用VSCode(VSCcode版本1.9.1)配置xdebug .

php.ini中

[Xdebug]
zend_extension = D:\php\ext\php_xdebug.dll
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.remote_log = D:\site\xlog.txt

我的默认php端口是3000. ($_SERVER['SERVER_PORT'] = 3000 我实际上可以在 localhost:3000 运行 phpinfo() 而Xdebug端口设置为 xdebug.remote_port = 9000

Xdebug日志:

Log opened at 2017-02-17 20:50:56
I: Connecting to configured address/port: localhost:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///D:/site/index.php" language="PHP" xdebug:language_version="7.1.0-dev" protocol_version="1.0" appid="11384" idekey="Admin"><engine version="2.5.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>

<- breakpoint_list -i 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>

<- breakpoint_list -i 2
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="2"></response>

<- breakpoint_set -i 3 -t exception -x *
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="113840001"></response>

<- run -i 4
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="4" status="stopping" reason="ok"></response>

<- stop -i 5
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stop" transaction_id="5" status="stopped" reason="ok"></response>

Log closed at 2017-02-17 20:50:56

launch.json:

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

}

对于以下测试代码:

$var = "test\n";
print $var;
var_dump($var);

我在调试控制台中得到了这个:

test D:\site\index.php:5: string(5) "test "

但是 no variables 在调试列表中..

我不知道为什么但变量没有出现在VSCode中 .

当我试图达到 localhost:3000 时...我得到的是:

Log opened at 2017-02-17 21:38:16
I: Connecting to configured address/port: localhost:9000.
E: Time-out connecting to client. :-(
Log closed at 2017-02-17 21:38:17

1 回答

  • 0

    Got it working (only tested with php version 7).

    按照步骤..

    vscode> debug> gear图标> launch.json

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

    vscode>文件>首选项> settings.json> WORKSPACE SETTINGS

    // Place your settings in this file to overwrite default and user settings.
    {
          "php.validate.executablePath": "C:\\Program Files (x86)\\php\\php7\\php.exe",
          "php.validate.enable":true
    }
    

    php.ini 将此添加到文件末尾(注意"zend_extension"中没有路径斜杠)

    [Xdebug]
    zend_extension = php_xdebug-2.5.4-7.0-vc14-nts.dll
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1
    xdebug.remote_handler=dbgp
    xdebug.remote_host=localhost
    xdebug.remote_port=9000
    xdebug.remote_log = C:\Temp\Xdebug_log.txt
    

    也看这个youtube指南:

    https://www.youtube.com/watch?v=xME6uHYTcLU

    Finally, when configuration is done, here is how to get the debugger in vs code to show the variable, watch, callstack:

    • 启动网络服务器(例如端口8080 ..只是不在端口9000上)

    • vscode>点击;启动debuggin(听Xdebug)
      在Chrome中

    • 点击RELOAD(这将触发并开始调试)完成 .

相关问题