【发布时间】:2012-04-15 16:34:14
【问题描述】:
我实现心跳如下
$.ajax({
cache:false,
timeout:8000,
type:"POST",
url:"someurl.php",
data:allFormValues,
error:function(){ alert("some error occurred") },
success:function(response){ //call some functions }
});
在服务器端
$time = time();
while(!proccessServer() && (time() - $time) < 60 )
{
sleep(5);
}
如果它返回false,它会调用一个函数,循环将休眠5秒,然后检查 但问题是这东西正在吃我的资源 CPU 这只是在 5 个用户测试它的时候
我之前用过
window.setInterval(function(){
//I call a function here
}, 5000);
但也因为请求太多,它正在吃资源
也许我的应用同时有 100K 在线 由于浏览器兼容性,我也没有考虑使用 websockets 你有什么建议来解决这个问题? 任何帮助表示赞赏
【问题讨论】:
标签: php ajax push comet pull-request