PhpStorm+Xdebug 只在使用外网IP时断点

PhpStorm+Xdebug hits a breakpoint only when using external IP address

使用 MacOS Sierra、PhpStorm 和 Xdebug,在端口 80 上配置 Web 应用程序(不是来自 PhpStorm 的 运行)。

当浏览到localhost:80/index.php时,PhpStorm不会在断点处停止,当访问外部IP192.168.1.2/index.php时,PhpStorm会命中断点。

我想使用 localhost 进行调试而不是外部 IP。

有没有办法让 PhpStorm 与 localhost 一起工作?

P.S. Visual Studio 代码在两种情况下都有效(因此我相信 Xdebug 和 PhpStorm 运行良好)。

[xdebug]
zend_extension = /usr/local/Cellar/php56/5.6.29_5/lib/php/extensions/debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.idekey=vagrant
xdebug.remote_host=0.0.0.0

试图将 xdebug.remote_host 设置为 127.0.0.1localhost,相同的行为。

调试时 localhost:80,xdebug 日志显示:

Log opened at 2017-01-03 14:06:36
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to ::1:9000.
W: Creating socket for '::1:9000', poll success, but error: Operation now in progress (19).
E: Could not connect to client. :-(
Log closed at 2017-01-03 14:06:36

使用 VS Code 时,没有错误,而是显示 xdebug I: Connected to client. :-)

xdebug.remote_connect_back 设置为 0(默认值)解决了问题。

Xdebug documentation:

If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request. It checks the $_SERVER['HTTP_X_FORWARDED_FOR'] and $_SERVER['REMOTE_ADDR'] variables to find out which IP address to use.

当 Xdebug 尝试连接到本地主机时,它使用了 PhpStorm 不支持的 TCPv6。 将 remote_connect_back 更改为 0 导致 Xdebug 使用 remote_host 值,使用 PhpStorm 支持的 TCPv4。