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

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?

  • 写回答

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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败