0

こんにちは、アプリケーションがサーバーの応答に基づいてコンテンツを更新するコメット (ロング ポーリング リクエスト) ベース アプリケーションを実装しました。

私の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分までリクエストをブロックすることです

提案はありますか??

4

1 に答える 1

0

セッションは私の問題でした。Zend_Session::writeClose(true);を追加して解決しました。

于 2012-12-29T10:07:57.040 に答える