【发布时间】:2021-02-28 20:28:45
【问题描述】:
我想尝试 Xdebug 3.0.0RC1 来探索发生了什么变化以及随之而来的新功能。我还在使用最新的 PhpStorm 2020.3 EAP,它支持 Xdebug 3,无需主要配置。下面是我对调试器的 PhpStorm 配置:
这是我为 Xdebug3 尝试过的配置:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal # here I tried several combinations like: "localhost", "127.0.0.1", "172.17.0.1"
xdebug.client_port=9001 # here I tried several ports 9003 included with no success
我也尝试过不添加 client_host/client_port 设置,但仍然失败。
我收到此错误:
Script php bin/console doctrine:cache:clear-metadata returned with error code 255
!! [17-Nov-2020 15:24:40 UTC] Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9001 (through xdebug.client_host/xdebug.client_port) :-(
!! [17-Nov-2020 15:24:41 UTC] PHP Fatal error: Method class@anonymous::__toString() must not throw an exception, caught Symfony\Component\DependencyInjection\Exception\AutowiringFailedException: in /var/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php on line 233
关于我的环境的一些信息:
- Fedora 33
- Docker 版本 19.03.13,构建 4484c46d9d
- PhpStorm 2020.3 EAP 构建 #PS-203.5784.36
这很奇怪(因为显然host.docker.internal 是我正在使用的 Docker 版本“不”支持的,但它可以工作)而且很奇怪,同时以下配置确实适用于 Xdebug 2,即使调试器正在监听一直传入连接:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9000
我在这里缺少什么?
注意:我已经应用了Xdebug开发者here提供的解决方案。
【问题讨论】:
-
你的操作系统是什么?
-
host.docker.internal在 Linux 上不受支持——仅 Windows 和 Mac——github.com/docker/for-linux/issues/264。自 Docker v20 -- github.com/docker/for-linux/issues/264#issuecomment-714253414 起将支持它。如果您想使用该主机名,则需要动态检测 IP 地址(上述链接有很多关于如何实现这一点的选项)。 -
@ReynierPM 您可能有其他选项(例如
xdebug.remote_connect_back = 1-- Xdebug 2 相当于 Xdebug 的 3xdebug.discover_client_host = true)。使用显式 IP 地址(硬编码).. 或动态检测。 -
@LazyOne 它也不起作用 :(
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 10.211.55.12:9001 -
刚刚花了整晚的时间在这上面工作。原来ufw已启用并且它阻塞了端口。
ufw allow 9003已修复此问题,但可能应该通过 IP/设备将其锁定