2017-01-02 56 views
2

使用MacOS Sierra,PhpStorm和Xdebug,在端口80上配置的Web应用程序(不是从PhpStorm运行)。仅当使用外部IP地址时,PhpStorm + Xdebug才会触发断点

当浏览到localhost:80/index.php时,PhpStorm不会在断点停止,当访问外部IP 192.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_host127.0.0.1本地主机,相同的行为。

当调试本地主机: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代码,没有错误和Xdebug显示,而不是I: Connected to client. :-)

+0

请分享您的PhpStorm设置。现在可能是您在PhpStorm中为IP地址创建了“调试服务器”条目 - 请在'Settings/Preferences |语言和框架| PHP | Servers'。如果它在那里都很好 - 收集xdebug相关日志(来自IDE和xdebug端)。 – LazyOne

+0

*(仅供参考)*与PhpStorm论坛相同 - https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000010444-PHPStorm-Xdebug-hits-a-breakpoint-only -when-using-external-IP-address – LazyOne

+0

感谢@LazyOne,尽管当PHPStorm检测到连接时(通过外部IP连接时),它们会自动创建,但我尝试过更改服务器设置。 – Ofiris

回答

5

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

Xdebug documentation

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

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