I implemented heartbeat as the following
$.ajax({
cache:false,
timeout:8000,
type:"POST",
url:"someurl.php",
data:allFormValues,
error:function(){ alert("some error occurred") },
success:function(response){ //call some functions }
});
and in the server side
$time = time();
while(!proccessServer() && (time() - $time) < 60 )
{
sleep(5);
}
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
I used before this
window.setInterval(function(){
//I call a function here
}, 5000);
but also it was eating the resources because of many requests
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