【问题标题】:PhpStorm+Xdebug hits a breakpoint only when using external IP addressPhpStorm+Xdebug 只有在使用外部 IP 地址时才会触发断点
【发布时间】:2017-05-16 08:13:37
【问题描述】:

使用 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 Code 在这两种情况下都适用(因此我相信 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.1 和 localhost,行为相同。

调试localhost:80时,xdebug log显示:

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. :-)

【问题讨论】:

  • 请分享您的 PhpStorm 设置。现在可能是您在 PhpStorm 中为 IP 地址创建了“调试服务器”条目——在Settings/Preferences | Languages & Frameworks | PHP | Servers 进行检查。如果一切顺利——收集与 xdebug 相关的日志(来自 IDE 和 xdebug 方面)。
  • (仅供参考) PhpStorm 论坛也一样 -- intellij-support.jetbrains.com/hc/en-us/community/posts/…
  • 感谢@LazyOne,我确实尝试过更改服务器设置,尽管它们是在 PHPStorm 检测到连接时自动创建的(通过外部 IP 连接时)。
  • 更新了问题,@LazyOne,在 xdeubg 日志之后,我可以看到将 'xdebug.remote_connect_back' 更改为 0 确实使 PHPStorm 和 xdebug 与 localhost 一起工作
  • 因为它现在有效——发布您的解决方案并附上解释作为答案——将对处于类似情况的其他用户有用(回复的帖子将更容易找到..另外它表明帖子包含有用的信息)

标签: phpstorm xdebug


【解决方案1】:

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

Xdebug documentation:

如果启用,xdebug.remote_host 设置将被忽略,Xdebug 将 尝试连接到发出 HTTP 请求的客户端。它检查 $_SERVER['HTTP_X_FORWARDED_FOR'] 和 $_SERVER['REMOTE_ADDR'] 变量 找出要使用的 IP 地址。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 2014-05-28
    相关资源
    最近更新 更多