我实现了心跳如下
$.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 你有什么建议解决这个问题?任何帮助表示赞赏