【发布时间】:2017-02-25 23:39:32
【问题描述】:
【问题讨论】:
标签: php debugging visual-studio-code xdebug visual-studio-debugging
【问题讨论】:
标签: php debugging visual-studio-code xdebug visual-studio-debugging
几分钟后找出我的机器上发生了什么,我想出了如何解决我的问题。
因为 xdebug 是基于端口 9000 运行的,而我在 Debug Console(VSCode)上看到消息 listen EADDRINUSE :::9000,我认为端口 @987654324 上运行着另一个进程@ 所以我检查了这个命令在它上面运行的进程
sudo netstat -nlp | grep :9000
上面的命令会告诉你什么进程在端口9000上运行,然后我得到这个结果
tcp6 0 0 :::9000 :::* LISTEN 14856/hhvm
HHVM默认接管了xdebug的端口,所以我需要关闭它的服务或更改端口号。
提示:
您也可以使用lsof查看特定端口上的进程
lsof -t -i :9000
【讨论】:
xdebug.remote_port 更改为您的新端口号,然后更改 VScode 上的 xdebug 配置。
我在开始使用 VSCode 时遇到了同样的问题。好吧,我花了 3 个小时才弄清楚到底是什么问题,我只是盯着一些逐步调试,比如正在使用的端口以及其他设置是什么。
最后我很幸运并得到了解决方案:) 所以我与大家分享。您可以查看我的发现以及您需要设置什么才能让 Xdebug 与 VSCode 一起工作。
在 VS Code 中设置 Xdebug 以实时调试您的 PHP 代码。按照分步说明正确设置 xdebug。
[Xdebug] zend_extension="FULL-XDEBUG-DLL-FILE-PATH"
示例
;zend_extension="d:\wamp64\bin\php\php7.1.9\zend_ext\php_xdebug-2.6.0beta1-7.1-vc14-x86_64.dll"
或
;zend_extension="d:\wamp64\bin\php\php7.1.9\ext\php_xdebug-2.6.0beta1-7.1-vc14-x86_64.dll"
xdebug.remote_enable=1
xdebug.remote_autostart = 1
xdebug.remote_port="9000"
xdebug.profiler_enable=1
xdebug.remote_host="localhost"
xdebug.profiler_output_dir="<tmp path>"
;Example
;xdebug.profiler_output_dir="d:\wamp64\tmp"
打开phpinfo并找到xdebug,如果找到则说明xdebug安装成功! 如果 Wamp Restart 但 localhost 未打开,则尝试更改 PORT。可以 PORT 被任何其他人使用 已经申请了。
示例 JSON - launch.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
}
]
}
"php.validate.run": "onType",
"php.validate.executablePath": "<Your-Full-PHP-Path>php.exe"
打开 PHP 项目文件夹并尝试调试代码..如果您收到以下错误
VS Code Debug 适配器进程意外终止
或
VS 代码控制台错误 -> 监听 EADDRINUSE::900)
这意味着 PORT 9000 当前正在被另一个程序使用,您可能正在运行 PHPStorm Xdebug 或任何其他使用 PORT 9000 的应用程序。尝试关闭 PHPStorm 或其他程序并再次尝试调试。 em>
仍然出现错误然后尝试查找使用 PORT 9000 的程序并杀死它们.. 仍然出现错误尝试更改 php.ini 和 launch.json 中的 PORT 并重新启动 wamp 和 VSCode。 p>
现在您可以看到 XDEBUG 在 VSCode 中运行。
> #### 测试示例代码
<?php
/*
|--------------------------------------------------------------------------
| PHP XDebug Code Example - VS Code
|--------------------------------------------------------------------------
|
| Information:
|
| VS Code :
| Version : 1.19.2
| Commit : 490ef761b76b3f3b3832eff7a588aac891e5fe80
| Date : 2018-01-10T15:55:03.538Z
| Shell : 1.7.9
| Renderer : 58.0.3029.110
| Node : 7.9.0
| Architecture : x64
|
| Windows : 10
|
| WAMP Server : 3.1.0
| PHP : 7.1.9
| APACHE : 2.4.27
| MySQL : 5.7.19
|
| PHP INI PATH : D:\wamp64\bin\apache\apache2.4.27\bin\php.ini
| [Xdebug]
| zend_extension = "d:\wamp64\bin\php\php7.1.9\zend_ext\php_xdebug-2.6.0beta1-7.1-vc14-x86_64.dll"
| xdebug.remote_enable = 1
| xdebug.remote_autostart = 1
| xdebug.remote_port = "9000"
| xdebug.profiler_enable = 1
| xdebug.remote_host = "localhost"
| xdebug.profiler_output_dir = "d:\wamp64\tmp"
|
*/
// first loop
for ($i=0; $i < 10; $i++) {
echo $i;
}
echo PHP_EOL;
// second loop
for ($i = 0; $i < 20; $i++)
{
echo $i;
}
/* End of file php-test.php */
/* Location: /wamp64/www/test/php-test.php */
谢谢:)
【讨论】:
xdebug.remote_autostart=on Arch linux 软件包中的默认 xdebug.ini 缺少此功能...谢谢!
我在旧版本的 VS Code 上遇到了这个错误,我更新到 v1.37.1 并修复了它。
更新 VS 代码我遇到 Access Denied 错误,它提示我一个对话框 Failed Delete Marker。我运行进程监视器并单击对话框中的重试,更新完成并正常工作。
【讨论】: