Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php server sent events

header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

while (true) {
  	$data = [
    	'name' => 'Rasmus Lerdorf'
    ]

  	echo "event: sse
";
  	echo "data: " . json_encode($data) . "

";
    echo str_pad('', 4096) . "
";
      
	ob_flush();
  	flush();
  	sleep(1);

  	if (connection_aborted()) {
    	break;
  	}
}
ob_end_flush();
 
PREVIOUS NEXT
Tagged: #php #server #events
ADD COMMENT
Topic
Name
2+5 =