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 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同