0
私はPHPのチャットスクリプトで長いポーリングを実装しようとしていますが、長いポーリングは元のものを待っているスリープ状態にするすべてのajaxリクエストを入れます。ajaxとjqueryとsymfony(ロングポーリングの問題)
私はsymfonyフレームワークで作業しています。
function whosTyping(person_id){
$.ajax({
type:'POST',
url:'/chat/whoisTyping',
data:'person_id='+person_id
dataType:'json',
success:function(resp){
if(resp == 'true') $('.is_typing').show();
else $('.is_typing').hide();
setTimeout(function(){
whosTyping(person_id)
},1000)
}
})
}
はPHP:
public function executeWhoisTyping(sfWebRequest $request) {
$this->setLayout(false);
$this->setTemplate(false);
sfConfig::set('sf_web_debug', false);
$person_id = $request->getParameter('person_id');
$target_person_id = $this->getUser()->getGuardUser()->getPerson()->getId();
$check = Doctrine_Core::getTable('Typing')->findByPersonIdAndTargetPersonId($person_id)->toArray();
while(empty($check)){
usleep(1000);
clearstatcache();
$check = Doctrine_Core::getTable('Typing')->findByPersonIdAndTargetPersonId($person_id)->toArray();
}
Doctrine_Core::getTable('Typing')->createQuery()
->delete()
->where('target_person_id = ?', $target_person_id)
->execute();
return $this->renderText(json_encode('true'));
}
そして、はい、私は定期的にAJAXを送信しようとしている
- - UPDATE
ここではいくつかのコードが
Javascriptをスニペットです長いポーリング応答を待ってキャンセルされます」