title: Ajax PHP Long Polling
body: <p>I have this simple long polling:</p>
  
  <pre><code>  function poll(){
           $.ajax({
               ...
               success: function(res){
                  $('#count').html(res);
                  poll();
               }
          });
       }
   poll();
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>session_start();
  $count = $_SESSION['count'];
  session_write_close();
  while(true){
      session_start();
      $newcount = $_SESSION['count'];
      session_write_close();
      if($newcount != $count){
          $count = $newcount;
          break;
      }
      sleep(1);
  }
  echo $count;
  </code></pre>
  
  <p>when ever the count session is updated it break out of the while sleep loop then echoes the new count then polls again. My questions is: is this right? does this code have side effects to the server?</p>