Hi, I'm trying to implement in Swoole Server but it returns nothing in my Network tab of Google Chrome. No Status, No Protocol, No Type and No Size. But it is working fine the terminal.
Here is the code...
$http->on('request', function (Request $request, Response $response) {
$response->header('Content-Type', 'text/event-stream');
$response->header('Cache-Control', 'no-cache');
$response->header('Connection', 'keep-alive');
$response->header('X-Accel-Buffering', 'no');
$response->end( (new SSE())->start(new Update(function () {
$time = date('Y-m-d H:i:s');
$news = [['id' => $time, 'title' => 'title ' . $time, 'content' => 'content ' . $time]]; // Get news from database or service.
if (empty($news)) {
return false; // Return false if no new messages
}
return json_encode(compact('news'));
}), 'news') );
});
Thank you in advance.