Yesterday, I plunged into Server-Sent events, as they were a great way to create news for the online game I am creating. I had a working script that could subscribe to my channel, and a script that could pull the news feed from the MySql database in a few minutes, but for some reason it disconnects the connection every time ... (and every 3 seconds rebuilds, which makes it no better than just using AJAX at specific time intervals, for example)
Used javascript:
var source = new EventSource('http://theobg.itselementary.site50.net/gamefeed.php'); source.onmessage = function(e) { $("#gamefeed").html(e.data); }
PHP I use:
<?php header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); header('Connection: keep-alive'); function sendMsg($id, $msg) { echo "id: $id" . PHP_EOL; echo "data: $msg" . PHP_EOL; echo PHP_EOL; ob_flush(); flush(); }
I watched all over the Internet, but everything seems to work fine with me, except that the connection is not "kept alive" and I have no idea why this ... can anyone help me?
Thanks in advance, Dalionzo
source share