【问题标题】:Visual Studio Code (VSCode) - Error: Debug Adapter Process Has Terminated UnexpectedlyVisual Studio Code (VSCode) - 错误:调试适配器进程意外终止
【发布时间】:2017-02-25 23:39:32
【问题描述】:

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

谁能帮我解决这个问题?

【问题讨论】:

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


    【解决方案1】:

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

    因为 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
    

    【讨论】:

    • 嗨@JackZhai 我肯定会的,但我需要等待 23 小时才能接受我自己的答案,谢谢 :)
    • 知道了,感谢您的警告,您现在可以将其标记为答案:)
    • @AdityaKresnaPermana 谢谢解答!您将 xdebug 更改为哪个端口?
    • @mrquad 在那种情况下,我没有更改 xdebug 的端口,而是更改了 HHVM 配置,因此它不会与 xdebug 进程冲突。但是如果您想尝试更改,请转到您的 php.ini 并将参数 xdebug.remote_port 更改为您的新端口号,然后更改 VScode 上的 xdebug 配置。
    • 我有另一个 VSCode 调试会话正在运行,所以重新启动 VSCode 并且这个错误消失了。
    【解决方案2】:

    我在开始使用 VSCode 时遇到了同样的问题。好吧,我花了 3 个小时才弄清楚到底是什么问题,我只是盯着一些逐步调试,比如正在使用的端口以及其他设置是什么。

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

    #VSCode & PHP 调试

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

    Gif 动作:


    如何使用 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,找到'Loaded Configuration File'就知道是什么了 php.ini 文件 wamp 使用
    • 打开 php.ini 文件并放在下面的代码

    [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"
    

    4。重启 WAMP 服务器

    打开phpinfo并找到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 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 */
    

    谢谢:)

    【讨论】:

    • 您应该在此处的答案中包含所有详细信息。到其他网站的链接可能会损坏并且不再有效。 stackoverflow 的用户不必通过站点外的链接来查找答案。像你这样名声在外的人应该已经知道了。
    • 我不会因为 Matthew Goheen 提到的同样原因投票赞成你的答案。
    • @MatthewGoheen 是的,你是对的,答案必须是这样,只有第 3 方链接不可靠,它们可能随时消失而没有任何事先警告。感谢把我拖向正确的方向:)
    • @NeerajSingh 非常好!
    • xdebug.remote_autostart=on Arch linux 软件包中的默认 xdebug.ini 缺少此功能...谢谢!
    【解决方案3】:

    我在旧版本的 VS Code 上遇到了这个错误,我更新到 v1.37.1 并修复了它。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 2019-03-09
      相关资源
      最近更新 更多