I have this SSE running and sending event to client every 1 second. The problem is the server stops responding to other client's requests while SSE is running.
//client
var time;
var source = new EventSource(url);
source.addEventListener('time', (e)=>{
time= e.data;
}, false);
//in my controller (CodeIgniter)
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
while(true){
echo "id: 12" . PHP_EOL;
echo "event: time\n";
echo "data: ".date('F j, Y g:i:s A ', time()). PHP_EOL;
echo PHP_EOL;
ob_flush();
flush();
if ( connection_aborted() ) break;
sleep(1);
};
Might be a problem with session lock. Try adding
session_write_close();abovesleep(1)statement