I have this simple long polling:
function poll(){
$.ajax({
...
success: function(res){
$('#count').html(res);
poll();
}
});
}
poll();
PHP:
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;
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?