嗨我已经实现了彗星(长轮询请求)基础应用程序,我的应用程序根据服务器响应更新内容
我的 php 代码如下,我的应用程序使用 zend 框架
ini_set('set_time_limit', 300);
//get zend session object
$myNamespace = new Zend_Session_Namespace();
//get zend_auth object
$auth=Zend_Auth::getInstance();
$requestTime=time();
$response=array();
$response["returnvalue"]="invalid";
//check for new event on server for 240 seconds else send response
do{
//call_function return true or false
$query=$this->call_function($auth->getIdentity()->user_id,$auth->getIdentity()->lastViewedTime);
//some code here
if(!$query){
//sleep for some time;
sleep(60);
}else{
//send response to server when something new has occured
$lastViewed=round(microtime(true) * 1000);
$user=$auth->getStorage()->read();
$user->lastViewedTime=$lastViewed;
$auth->getStorage()->write($user);
$response["returnvalue"]="valid";
break;
}
}while(true && (time()-$requestTime)<240);
header("Content-Type: application/json");
echo json_encode($response);exit;
我的 JavaScript 代码是
var counter = {
'poll' : function() {
$.ajax({
type: "GET",
url: '/long-polling',
data:"a=b",
dataType:"json",
async:true,
success:function(response){
counter.update(response);
},
error: function(XMLHttpRequest,textStatus){
alert("This Operation Could not be Completed. Please check your Internet Connection and try Again. If problem persists please contact Support");
}
});
},
'update' : function(json) {
alert(json.data);
counter.poll();
}
};
$(document).ready(function(){
counter.poll();
});
我的 apache 配置是
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 240
MaxClients 150
MaxRequestsPerChild 4
长轮询工作正常,但问题是当浏览器发送其他请求以加载其他元素时,服务器上的图像,服务器直到 5 分钟才回复/阻止请求
有什么建议吗??