Xdebug 忽略断点(浏览器和 CLI)

Xdebug ignores breakpoints (browser and CLI)

我一直在尝试使用 nginx(或 cli)在 PHP 7.2 上设置 Xdebug,但到目前为止无济于事。断点将被忽略。尝试使用 PhpStorm 激活它们并手动使用 xdebug_break().

所有的方法都至少触发了 Xdebug,正如错误日志所说(您可以在下图中看到有问题的代码),但没有任何反应:

Log opened at 2018-04-21 07:50:31
I: Connecting to configured address/port: 127.0.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///Users/riseandcry/Projects/php/jobApplication/index.php" language="PHP" xdebug:language_version="7.2.2" protocol_version="1.0" appid="9859" idekey="PHPSTORM"><engine version="2.6.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2018 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="break" reason="ok"><xdebug:message filename="file:///Users/riseandcry/Projects/php/jobApplication/index.php" lineno="4"></xdebug:message></response>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

Log closed at 2018-04-21 07:50:31

我的配置是这样的:

zend_extension=/usr/local/Cellar/php72/7.2.2_13/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_connect_back=0
xdebug.idekey="PHPSTORM"
xdebug.remote_log=/Users/riseandcry/Projects/php/xdebug/xdebug.log
xdebug.extended_info=1
xdebug.force_display_errors=1

我没有在 PHP 中加载任何其他扩展,并且 PhpStorm 验证显示一切正确:

此外,我已经用各种方法重新安装了所有东西(PHP、nginx、Xdebug),但仍然没有用。我的猜测是 Xdebug 或配置有问题,但不知道是什么。

非常感谢您的帮助。我还在 SO 和其他论坛上阅读了几乎所有相关问题,因为我在这里,你可以猜到结果......

您正在使用 Mac 并且您正在使用 nginx...这意味着 很可能您确实有 php- fpm 安装和 运行。问题是 php-fpm 也默认使用 TCP 9000 端口...所以现在 Xdebug 正在连接那里而不是 PhpStorm(xdebug 日志在这里给出了一个很好的提示,如果你之前看到过这样的响应)。

不幸的是,PhpStorm 无法(出于任何原因)检测到 Xdebug 端口已被 Mac 上的另一个应用程序使用(但在 Windows/Linux 上没问题)。

您可以使用此类命令手动验证(查找使用 Xdebug 端口的条目并查看进程名称):

sudo lsof -nP -iTCP -sTCP:LISTEN

解决方案 是在 php.ini 和 PhpStorm 设置中将 Xdebug 端口更改为 9001(或任何其他有意义的数字)。

P.S. 您需要重新启动所有调试会话/禁用和启用 "phone handle" 图标(如果您正在使用它)。或者只是重新启动 IDE.