Skip to content

Instantly share code, notes, and snippets.

@alherd-by
Created March 8, 2017 11:47
Show Gist options
  • Save alherd-by/a5db1e46ea4610070f248912986828e1 to your computer and use it in GitHub Desktop.
Save alherd-by/a5db1e46ea4610070f248912986828e1 to your computer and use it in GitHub Desktop.
$response = new StreamedResponse(function () {
while (true) {
echo 'event: message' . PHP_EOL;
echo 'data: ' . \json_encode(['data' => 1]) . PHP_EOL;
echo PHP_EOL . PHP_EOL;
ob_flush();
flush();
sleep(2);
};
});
$response->headers->set('Content-Type', 'text/event-stream;charset=utf-8');
$response->headers->set('Cache-Control', 'no-cache');
$response->headers->set('X-Accel-Buffering', 'no');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment