Visual Studio代码(VSCode) - 错误:调试适配器进程意外终止

时间:2016-10-17 04:57:51

标签: php debugging visual-studio-code xdebug visual-studio-debugging

我正在努力解决此错误消息。有时,在升级或重新启动编辑器后,我无法在Visual Studio代码上运行 xdebug 。这是错误的屏幕截图:

enter image description here

任何人都可以帮我吗?

3 个答案:

答案 0 :(得分:6)

几分钟后我发现我的机器上发生了什么,我想出了如何解决我的问题。

因为 xdebug 正在基于端口9000运行,并且我在Debug Console(VSCode)上看到消息listen EADDRINUSE :::9000,我认为还有另一个进程在端口9000上运行,所以我通过这个命令检查在它上面运行的进程

sudo netstat -nlp | grep :9000

上面的命令将显示在端口9000上运行的进程,然后我得到此结果

tcp6       0      0 :::9000                 :::*                    LISTEN      14856/hhvm

HHVM 默认接管xdebug端口,因此我需要关闭服务或更改端口号。

<强>提示:

您还可以使用lsof查看特定端口上的进程

lsof -t -i :9000

答案 1 :(得分:3)

当我开始使用VSCode时,我遇到了同样的问题。好吧,我花了3个小时来弄清楚究竟是什么问题,我只是一步一步地调试,比如使用什么端口以及其他设置。

最后我很幸运并得到了解决方案:)所以我与大家分享。您可以查看我的调查结果以及您需要设置什么才能使Xdebug与VSCode一起使用。

#VSCode&amp; PHP调试

在VS Code中设置Xdebug以便在运行时调试PHP代码。按照分步说明正确设置xdebug。

Gif动作:

enter image description here

如何使用VSCode设置PHP调试(xdebug)?

1。 First of all Install VSCode

2。 Install PHP Debug Adapter for Visual Studio Code

3。 Install XDebug in WAMP

  • 在浏览器中打开phpinfo
  • 复制视图代码
  • 粘贴https://xdebug.org/wizard.php
  • 下载建议的xdebug dll文件
  • 将dll文件粘贴到当前版本的php文件夹ext或 zend_ext文件夹
  • 打开phpinfo并找到“已加载的配置文件”&#39;知道是什么 php.ini文件使用
  • 打开php.ini文件&amp;放在代码下面
  

[Xdebug] zend_extension =&#34; FULL-XDEBUG-DLL-FILE-PATH&#34;

<强> 实施例

  

;的zend_extension =&#34; d:\ wamp64 \ BIN \ PHP中\ php7.1.9 \ zend_ext \ php_xdebug-2.6.0beta1-7.1-VCl 4-x86_64.dll&#34;

<强> OR

  

的zend_extension =&#34; d:\ wamp64 \ BIN \ PHP中\ php7.1.9 \分机\ php_xdebug-2.6.0beta1-7.1-VCl 4-x86_64.dll&#34;

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"

4。重启WAMP服务器

  

打开phpinfo&amp;找到xdebug,如果找到,那么你已经成功安装了xdebug!   如果Wamp Restart但是localhost没有打开则尝试更改PORT。可以通过任何其他方式使用PORT   申请已经。

How can you find out which process is listening on a port on Windows?

Setup XDebug in VSCode

  

示例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
        }
    ]
}

5。更新PHP的VSCode设置以添加PHP可执行路径

"php.validate.run": "onType",
"php.validate.executablePath": "<Your-Full-PHP-Path>php.exe"

6。保存并重新启动VSCode

打开PHP项目文件夹并尝试调试代码。如果您收到以下错误

  

VS代码调试适配器进程意外终止

  

VS代码控制台错误 - &gt;听EADDRINUSE :: 900)

这意味着PORT 9000目前正由另一个程序使用,您可能已运行PHPStorm Xdebug或任何其他使用PORT 9000的应用程序。尝试关闭PHPStorm或其他程序并尝试再次调试。

仍然收到错误,然后尝试找到使用PORT 9000的程序并杀死它们..仍然得到错误尝试更改php.ini和launch.json中的PORT并重新启动wamp和VSCode。

现在您可以看到XDEBUG在VSCode中工作。

<强>&GT; ####示例代码测试

<?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 */

谢谢:)

答案 2 :(得分:0)

我在VS Code的旧版本中遇到此错误,我更新到v1.37.1并修复了该错误。

更新VS Code我遇到一个 Access Denied 错误,它提示对话框 Failed Delete Marker 。我运行进程监视器,然后在对话框中单击“重试”,更新完成并正常工作。