title: How does HTML5 server sent events works?
body: <p>I am trying to understand how does HTML5 server side event works ? In the below code why would it not print Hello ? But if i remove the comments on the server side time line in php it would work and keep displaying the server side time? </p>
  
  <p>HTML5 </p>
  
  <pre><code>&lt;div id="result"&gt;&lt;/div&gt;
  
          &lt;script&gt;
  
      if(typeof(EventSource)!=="undefined")
        {
        var source=new EventSource("php/demo_sse.php");
        source.onmessage=function(event)
          {
          document.getElementById("result").innerHTML+=event.data + "&lt;br&gt;";
          };
        }
      else
        {
        document.getElementById("result").innerHTML="Sorry, your browser does not support server-sent events...";
        }
       &lt;/script&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  header('Content-Type: text/event-stream');
  header('Cache-Control: no-cache');
  
  $time = date('r');
  echo "Hello";
  //echo "data: The server time is: {$time}\n\n";
  flush();
  ?&gt;
  </code></pre>