Search the Community
Showing results for tags 'server-side-events'.
-
Hi i am using HTML5 Server-Sent Events Actually i need to show notification ( new record enter and which are unread ) thats when any new record is insert in database ( php / mysql ) So for testing purpose i just tried with count of total row. but getting below error message in my localhost : Firefox can't establish a connection to the server at http://localhost/project/folder/servevent/demo_sse.php.line is : var source = new EventSource("demo_sse.php"); WHAT I HAVE TRIED : index.php <script>if(typeof(EventSource) !== "undefined") {var source = new EventSource("demo_sse.php");source.onmessage = function(event) {document.getElementById("result").innerHTML = event.data;};} else {document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";}</script> <div id="result"></div> demo_sse.php <?phpheader('Content-Type: text/event-stream');header('Cache-Control: no-cache');$db = mysql_connect("localhost", "root", ""); // your host, user, passwordif(!$db) { echo mysql_error(); }$select_db = mysql_select_db("testdatase"); // database nameif(!$select_db) { echo mysql_error(); }$time = " SELECT count( id ) AS ct FROM `product` ";$result = mysql_query($time);$resa = mysql_fetch_assoc($result);echo $resa['ct'];flush();?> please let me know what going wrong. I know for notification we can use Ajax with some interval time , but i don't want such thing. As i have N number of records and which may slow my resources.