dongranding3909
2018-02-01 21:58
浏览 65
已采纳

PhpStorm + Xdebug远程调试冻结了

I have set PHP debugging with Xdebug on PhpStorm to hit a localhost. Everything works fine with "smart PHP listening" or manual debug run unless I have got to the point where code looks like

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

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

and got stuck on a line

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

with an error message

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

but when I run debug after that line will pass all work fine.

PhpStorm and Xdebug has already set

  • Settings | PHP | Debug | Max simultaneous connections --> 5.

xdebug.remote_autostart = 1

Any clue why Xdebug hangs on it when without debugging it can pass w/o any issue?

图片转代码服务由CSDN问答提供 功能建议

我已经在PhpStorm上使用Xdebug设置了PHP调试以命中localhost。 “智能PHP监听”或手动调试运行一切正常,除非我已经到了代码看起来像

  $ aOptions = array(
'htt'=>  ; array(
'header'=>“Content-Type:application / x-www-form-urlencoded 
 
 $ 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 /& amp; q [] = / 0 /):无法打开流:HTTP请求失败!

但是当我运行调试后该行将通过 一切正常。

PhpStorm和Xdebug已经设置

  • 设置| PHP | 调试| 最大同时连接 - > 5.

    xdebug.remote_autostart = 1

    任何线索,为什么Xdebug挂在它上面 没有调试它可以传递任何问题吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doudie2693 2018-02-02 17:07
    已采纳

    Based on JetBrains documentation for simultaneous debugging sessions I was able to get it fixed by adding suggested code to start debugger session for child requests as follow

    $aOptions = array (
            'http' => array (
                    'header' => "Content-Type: application/x-www-form-urlencoded
    $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 );
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongqie2355 2018-02-01 22:03

    You're calling localhost also in the file_get_contents() call. Is it the same port? If the xdebug is kicking in there too, then that request will be held (won't complete) and eventually the file_get_contents will time out.

    Is that code also accessible from PHP Storm? If so, you should jump in to that. Otherwise try running with cookie-triggered xdebug, so only the main request triggers it.

    xdebug.remote_autostart = 1 means When this setting is set to 1, Xdebug will always attempt to start a remote debugging session and try to connect to a client, even if the GET/POST/COOKIE variable was not present.[1] so that indicates it might be this

    I think you just want xdebug.remote_enable = 1 then use the extension/plugin for your browser (most browsers have an enable/disable xdebug plugin) to trigger xdebug only on your main request

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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题