laravel server sent events

Solutions on MaxInterview for laravel server sent events by the best coders in the world

showing results for - "laravel server sent events"
Maria
10 Sep 2019
1$loopTime = 1;
2$response = new StreamedResponse(static function () use ($loopTime) {
3    while (true) {
4      	$data = [
5        	'name' => 'Taylor Otwell'
6        ]
7      
8      	echo "event: sse\n";
9      	echo "data: " . json_encode($data) . "\n\n";
10        echo str_pad('', 4096) . "\n";
11      
12    	ob_flush();
13      	flush();
14      	sleep($loopTime);
15
16      	if (connection_aborted()) {
17        	break;
18      	}
19    }
20    ob_end_flush();
21}
22                                 
23$response->headers->set('Content-Type', 'text/event-stream');
24$response->headers->set('Cache-Control', 'no-cache');
25return $response;