我在启动PhpStorm调试应用程序时遇到了一些问题。
当我访问调试应用程序的URL时,会为通知系统生成额外的事件源请求(SSE)。但是当调试正常时,它会导致一个问题,我不能刷新页面,它只是无限加载--我没有任何断点可以确定。在我停止调试会话后,它会立即加载。
到底怎么回事?我可以以某种方式禁用此特定URL的xdebug吗?
我的这些通知代码如下所示:
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();
}
发布于 2018-11-02 16:24:46
我在使用xdebug调试SSE时遇到了同样的问题。解决方法是在离开页面时关闭事件源。
假设您在客户端使用javascript请求eventsource,例如
let eventSource = new EventSource("moreAction.php")
放一些类似这样的东西
$(window).on('beforeunload', function(){
eventSource.close();
});
在你的页面上。
顺便说一句,在你的eventsource循环中使用while(1)
不是一个好主意,因为它会无限循环,完全符合你正在经历的行为。30-120s范围内的超时是合理的,即使eventsource没有关闭,您也会允许继续调试吗?毕竟,它正在自动重新连接。
https://stackoverflow.com/questions/47099931
复制相似问题