Created
March 8, 2017 11:47
-
-
Save alherd-by/a5db1e46ea4610070f248912986828e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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