我已经在我的 Laravel 应用程序中实现了 SSE。它工作正常。但是,它会在执行 SSE 的时间内阻止 Web 应用程序。
public function index(Request $request)
{
$response = new \Symfony\Component\HttpFoundation\StreamedResponse(function() use ($request) {
while(true) {
$data = $this->getData($request->currency);
if ($data->hasChanged) {
echo 'data: ' . json_encode($data->rates) . "\n\n";
ob_flush();
flush();
}
sleep(0.5);
}
});
$response->headers->set('Content-Type', 'text/event-stream');
$response->headers->set('X-Accel-Buffering', 'no');
$response->headers->set('Cach-Control', 'no-cache');
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
我也试过
session_write_close();
但是没用
在 Laravel 中是否有修复它的解决方案?