【问题标题】:Xdebug does not stop on breakpoints - PHP centos DockerXdebug 不会在断点处停止 - PHP centos Docker
【发布时间】:2020-02-01 04:58:58
【问题描述】:

我正在尝试使用 docker、X-debug2.7.2、centos 和 php7.3.7 调试 Laravel 应用程序,但是不遵守断点。使用以下消息更新日志。

[41] Log opened at 2019-10-02 21:09:33
[41] I: Connecting to configured address/port: docker.for.win.localhost:9000.
[41] I: Connected to client. :-)
[41] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/public/index.php" language="PHP" xdebug:language_version="7.3.6" protocol_version="1.0" appid="41"><engine version="2.7.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>
[41]
[41] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
[41]
[41] Log closed at 2019-10-02 21:09:34

XDebug 配置

xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_enable = 1
xdebug.remote_host = docker.for.win.localhost
xdebug.remote_log = "/tmp/xdebug.log"
xdebug.remote_port = 9000

Vscode 配置

        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/var/www": "${workspaceRoot}"
              }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000,
            "pathMappings": {
                "/var/www": "${workspaceRoot}"
            }
        }

更新

经过多次尝试,我已将 x-debug 配置中的 remote_host 设置为我本地机器的 IP,并且它工作正常。

对于那些相信别名 host.docker.internal 会起作用的人来说,它没有。所以我所做的是为 remote_host 键设置一个虚构的名称,并在 docker-compose 中将其配置为具有本地 IP 的额外主机。

我认为这不是一个好的解决方案,因为使用此配置文件的每个人都需要在本地进行更改。所以我想知道你们是否有更好的解决方案。

【问题讨论】:

  • 情况不一样。在创建这个之前,我已经尝试了引用主题中提到的所有步骤。我不确定操作系统对这个问题的影响,但是,我之前使用的直接来自 PHP docker hub 存储库的图像工作正常,另一方面,使用 centOS 的图像没有。

标签: php docker visual-studio-code centos xdebug


【解决方案1】:

这可能表明有其他东西正在侦听端口 9000。您使用的是 PHP-FPM 吗?如果是这样,请将 PHP-FPM 端口更改为其他端口或 Xdebug 端口。您的 IDE 有一个设置("port": 9000,两次),在 php.ini 中您可以使用 xdebug.remote_port=9001(作为示例)。如果您更改了php.ini(或90-xdebug.ini,或其他任何名称),请务必重新启动您的网络服务器。

【讨论】:

  • 我在发布这个问题之前已经尝试过了,但没有成功。日志显示docker和IDE的连接已经建立,但是不知道为什么IDE中没有高亮断点。使用您的建议,它没有连接到客户端,并且 Xdebug 记录如下。 ``` [57] W:为 'docker.for.win.localhost:9001' 创建套接字,轮询成功,但错误:操作正在进行中(29)。 [57] W:为“docker.for.win.localhost:9001”创建套接字,连接:无法分配请求的地址。 [57] E:无法连接到客户端。 :-( ```
【解决方案2】:

这可能是一个有趣的问题,但您是否使用浏览器插件与 xdebug 通信?比如“调试”(firefix)或“Xdebug-helper”(chrome)

【讨论】:

  • 没有。我没有使用任何其他插件。
猜你喜欢
  • 2011-04-30
  • 2018-03-31
  • 1970-01-01
  • 2015-09-11
  • 2018-07-23
  • 2019-03-31
  • 2012-12-15
  • 2014-11-22
  • 2014-06-19
相关资源
最近更新 更多