2017-01-02 42 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。