Event Stream handling

Discussing Html . Code , Software , other

Moderators: egami, macek, gesf

Post Reply
php-forum Active User
php-forum Active User
Posts: 29
Joined: Sat Dec 26, 2015 12:18 pm

I am trying to get server sent event streams working.

As a test, I placed the following in a php file:

Code: Select all

header('Content-Type: text/event-stream');
header('Cache-Control: no-cache'); // recommended to prevent caching of event data.

function sendMsg($msg) {

 echo "data: $msg" . PHP_EOL;
 echo PHP_EOL;


sendMsg('server time: ' . date("h:i:s"));
When I load the page into FireFox (95.0.2 (64-bit)), it asks me if I want to save or open the file. Obviously it isn't handling the event stream properly (or my code is wrong)
Post Reply