首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用事件源进行Xdebug

使用事件源进行Xdebug
EN

Stack Overflow用户
提问于 2017-11-04 00:03:26
回答 1查看 84关注 0票数 1

我在启动PhpStorm调试应用程序时遇到了一些问题。

当我访问调试应用程序的URL时,会为通知系统生成额外的事件源请求(SSE)。但是当调试正常时,它会导致一个问题,我不能刷新页面,它只是无限加载--我没有任何断点可以确定。在我停止调试会话后,它会立即加载。

到底怎么回事?我可以以某种方式禁用此特定URL的xdebug吗?

我的这些通知代码如下所示:

代码语言:javascript
运行
复制
public function moreAction()
{
    ob_start();
    $maxId = $this->request->getQuery('maxId', 'int');
    header('Cache-Control: no-cache');
    header("Content-Type: text/event-stream\n\n");
    while (1) {
        $result = $this->notificationService->more($maxId);
        if (count($result) > 0) {
            foreach ($result as &$row) {
                if (!empty($row['data'])) {
                    $row['data'] = json_decode($row['data'], true);
                }
            }
            $maxId = $result[0]['id'];
            echo "event: message\n";
            echo "data:".json_encode($result);
            echo "\n\n";
            $this->doFlush();
        }
        sleep(5);
    }
}

protected function doFlush()
{
    if (!headers_sent()) {
        // Disable gzip in PHP.
        ini_set('zlib.output_compression', 0);
        // Force disable compression in a header.
        // Required for flush in some cases (Apache + mod_proxy, nginx, php-fpm).
        header('Content-Encoding: none');
    }
    // Fill-up 4 kB buffer (should be enough in most cases).
    echo str_pad('', 4 * 1024);
    // Flush all buffers.
    do {
        $flushed = @ob_end_flush();
    } while ($flushed);
    @ob_flush();
    flush();
}
EN

回答 1

Stack Overflow用户

发布于 2018-11-02 16:24:46

我在使用xdebug调试SSE时遇到了同样的问题。解决方法是在离开页面时关闭事件源。

假设您在客户端使用javascript请求eventsource,例如

代码语言:javascript
运行
复制
let eventSource = new EventSource("moreAction.php")

放一些类似这样的东西

代码语言:javascript
运行
复制
$(window).on('beforeunload', function(){
    eventSource.close();
});

在你的页面上。

顺便说一句,在你的eventsource循环中使用while(1)不是一个好主意,因为它会无限循环,完全符合你正在经历的行为。30-120s范围内的超时是合理的,即使eventsource没有关闭,您也会允许继续调试吗?毕竟,它正在自动重新连接。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47099931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档