簡體   English   中英

PhpStorm + Xdebug遠程調試凍結

[英]PhpStorm + Xdebug remote debugging froze

我已經在PhpStorm上使用Xdebug設置了PHP調試功能來訪問本地主機。 通過“智能PHP偵聽”或手動調試運行,一切都可以正常工作,除非我到達代碼看起來像這樣的地步

$aOptions = array (
        'http' => array (
                'header' => "Content-Type: application/x-www-form-urlencoded\r\n$sBits",
                'method' => 'POST',
                'content' => http_build_query ( $aData )
        )
);

$rContext = stream_context_create ( $aOptions );
$sResult = file_get_contents ( $sUrl, false, $rContext );
return \json_decode ( $sResult );

並卡在一條線上

$sResult = file_get_contents ( $sUrl, false, $rContext );

帶有錯誤信息

file_get_contents(http://localhost:8888/data/?/Ajax/&q[]=/0/): failed to open stream: HTTP request failed!

但是當我在那行之后運行debug時,一切工作都會順利進行。

PhpStorm和Xdebug已經設置

  • 設置| PHP | 調試| 最大同時連接數-> 5。

xdebug.remote_autostart = 1

有什么線索可以解釋為什么Xdebug在沒有調試的情況下就掛在它上面而沒有任何問題?

您也在file_get_contents()調用中調用localhost。 是同一個端口嗎? 如果xdebug也加入其中,那么該請求將被保留(不會完成),最終file_get_contents將超時。

可以從PHP Storm中訪問該代碼嗎? 如果是這樣,您應該跳進去。 否則,請嘗試使用由Cookie觸發的xdebug運行,因此只有主請求才觸發它。

xdebug.remote_autostart = 1表示將此設置設置為1時,即使不存在GET / POST / COOKIE變量,Xdebug也會始終嘗試啟動遠程調試會話並嘗試連接到客戶端。 [1]表示可能是這個

我認為您只希望xdebug.remote_enable = 1然后使用瀏覽器的擴展名/插件(大多數瀏覽器都具有啟用/禁用xdebug插件的功能)僅在您的主要請求上觸發xdebug

[1] https://xdebug.org/docs/remote

根據同時進行調試會話的 JetBrains文檔,我可以通過添加建議的代碼以啟動子請求的調試器會話來解決此問題,如下所示

$aOptions = array (
        'http' => array (
                'header' => "Content-Type: application/x-www-form-urlencoded\r\n$sBits",
                'method' => 'POST',
                'content' => http_build_query ( $aData )
        )
);

$debuggingQuerystring = '';
if (isset($_GET['XDEBUG_SESSION_START'])) { // xdebug
     $debuggingQuerystring = '?XDEBUG_SESSION_START=' . $_GET['XDEBUG_SESSION_START'];
}
if (isset($_COOKIE['XDEBUG_SESSION'])) { // xdebug (cookie)
     $debuggingQuerystring = '?XDEBUG_SESSION_START=PHPSTORM';
}

$rContext = stream_context_create ( $aOptions );
$sResult = file_get_contents ( $sUrl.$debuggingQuerystring, false, $rContext );
return \json_decode ( $sResult );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM