title: Long pulling PHP & AJAX - Server Performance
body: <p>I implemented heartbeat as the following </p>
  
  <pre><code>$.ajax({
      cache:false,
      timeout:8000,  
      type:"POST",
      url:"someurl.php",
      data:allFormValues,
      error:function(){ alert("some error occurred") },
      success:function(response){ //call some functions  }
     });
  </code></pre>
  
  <p>and in the server side </p>
  
  <pre><code>$time = time();
          while(!proccessServer() &amp;&amp; (time() - $time) &lt; 60 )
          {
              sleep(5);
          }
  </code></pre>
  
  <p>and simply it call a function if it returns false the loop will sleep for more 5 seconds and then check 
  but the problem is this thing is eating my resources CPU 
  and this was only when 5 users testing it </p>
  
  <p>I used before this </p>
  
  <pre><code>window.setInterval(function(){
    //I call a function here 
  }, 5000);
  </code></pre>
  
  <p>but also it was eating the resources because of many requests </p>
  
  <p>and maybe my app have 100K online at the same time 
  also I am not thinking about using websockets because of browsers compatibility 
  What do you suggest to solve this ? 
  any help is appreciated </p>