title: Symfony StreamedResponse Server Sent Event blocks requests
body: <p>I did an implementation of Server Sent Event (SSE) with StreamedResponse in Symfony. So when an event occurs a message is saved in the session, this message will be notified to the user.
  The problem is when the page that contains the client code is executed, it blocks all web requests to the application until the SSE connection is closed due to Maximum execution time.</p>
  
  <p>Server side code:</p>
  
  <pre><code>public function notificationAction() {
      $response = new StreamedResponse(function() {
          while(true) {
              $message = "";
  
              $messagesNotification = $this-&gt;get('session')-&gt;getFlashBag()-&gt;get('message_notification');; // code that search notifications from session
              if(count($messagesNotification)&gt;0){
                  foreach ( $messagesNotification as $messageNotification ) {
                      $message .= "data: " . messageNotification  . PHP_EOL;
                  }
                  $message .= PHP_EOL;
                  echo $message;
                  ob_flush();
                  flush();
  
              }
              sleep(8);
          };
  
      });
  
      $response-&gt;headers-&gt;set('Content-Type', 'text/event-stream');
      $response-&gt;headers-&gt;set('Cache-Control', 'no-cache');
      return $response;
  }
  </code></pre>
  
  <p>Client side code:</p>
  
  <pre><code>&lt;script&gt;
      var path = '/path';
      var source = new EventSource(path);
      source.onmessage = function(e) {
          // notification html
      };
      source.onerror = function(e) {
          // notification html
      };
  &lt;/script&gt;
  </code></pre>
  
  <p>I would like to know if this is a good implementation of SSE, and how to make the SSE call not to block requests.</p>
  
  <p>I'm using symfony 2.6 and Firefox as the browser.</p>
  
  <p>Thanks in advance for your help.</p>