我有这个简单的长轮询:
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;
当计数会话更新时,它会跳出while睡眠循环,然后回显新计数,然后再次轮询。我的问题是:这是对的吗?这段代码对服务器有副作用吗?