title: HTML5 Server-Sent Events onerror showing up every 3 seconds
body: <p>I'm new on SSE and I'm following the <a href="http://www.w3schools.com/html/html5_serversentevents.asp" rel="noreferrer">w3schools tutorial</a>. I added some code to their example so I can see when the connection is opened and when some error occours. Here is my code:</p>
  
  <pre><code>&lt;script&gt;
  var source = new EventSource("sse.php");                        
  source.addEventListener('message', function(e) {
      console.log("onmessage");           
      document.getElementById("result").innerHTML += event.data + "&lt;br&gt;";     
  }, false);
  
  source.addEventListener('open', function(e) {
      console.log("onopen");
  }, false);
  
  source.addEventListener('error', function(e) {
      console.log('error '+e.readyState);
  }, false);
  
  &lt;/script&gt;
  </code></pre>
  
  <p>And my server-side code:</p>
  
  <pre><code>&lt;?php
  header('Content-Type: text/event-stream');
  header('Cache-Control: no-cache');
  
  $time = date('r');
  echo "data: The server time is: {$time}\n\n";
  flush();
  ?&gt;
  </code></pre>
  
  <p>The documentation says that </p>
  
  <blockquote>
    <p>A server-sent event is when a web page automatically gets updates from a server. This was also possible before, <strong>but the web page would have to ask if any updates were available. With server-sent events, the updates come automatically.</strong></p>
  </blockquote>
  
  <p>But the console shows us the opposite:</p>
  
  <p><a href="https://i.stack.imgur.com/ukcl8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ukcl8.png" alt="enter image description here"></a></p>
  
  <p>The client-side is requesting a new connection, getting the message, an error is occurring and the connection is closed. This is repeated every 3 seconds. Why is this happening?</p>