2011-11-09 2 views
0

PHP 폴링 스크립트에서 긴 폴링을 구현하려고하지만 긴 폴링은 원래 Ajax 요청을 대기하는 모든 Ajax 요청을 넣습니다.ajax 및 jquery 및 symfony (긴 폴링 문제)

나는 현재 심포니 프레임 워크로 작업하고 있습니다.

아이디어가 있으십니까?

- - UPDATE 여기

는 일부 코드가

를 니펫

자바 스크립트입니다 :

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')); 
} 

그리고 그래 내가 정기적으로 아약스를 보내려고 해요 요청이지만 긴 폴링 응답을 기다리는 동안 취소됩니다. "

답변

1

그건 괜찮 사람은 나는 것은

때문에 작업 기능이되고 난 session_write_close()를 사용하여 현재 세션을 종료했다가 심포니와 함께 작동하는 것입니다

그것을 알아 냈 follwing을

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,$target_person_id)->toArray(); 
    while(empty($check)){ 
     usleep(100000); 
     clearstatcache(); 
     session_write_close(); 
     $check = Doctrine_Core::getTable('Typing')->findByPersonIdAndTargetPersonId($person_id,$target_person_id)->toArray();    
    } 

    return $this->renderText(json_encode(!empty($check) ? 'true' : 'false')); 
} 

도움이 되길 바랍니다.