开发者

Zend Imap Connection timeout

I'm using Zend framework provided IMAP classes to access gmail messages over imap. I access the message headers of all the messages in the inbox one by one and index them locally. The script works fine for inboxes with messages less than 10000. For larger inboxes the script looses the connection, probably a timeout.

Here is the stack trace:

Exception Message: cannot read - connection closed?

trace:

#0 /home/dev/trunk/Zend/Mail/Protocol/Imap.php(168): Zend_Mail_Protocol_Imap->_nextLine()

#1 /home/dev/trunk/Zend/Mail/Protocol/Imap.php(285): Zend_Mail_Protocol_Imap->_nextTaggedLine(NULL)

#2 /home/dev/trunk/Zend/Mail/Protocol/Imap.php(587): Zend_Mail_Protocol_Imap->readLine(NULL, 'TAG103')

#3 /ho开发者_开发技巧me/dev/trunk/Zend/Mail/Storage/Imap.php(353): Zend_Mail_Protocol_Imap->fetch('UID', 12267)

#4 /home/dev/trunk/model/gmail_imap_oauth.class.php(121): Zend_Mail_Storage_Imap->getUniqueId(12267)

Is there a possible way to keep the connection alive for a longer duration ? I'm running this script via command line and tried increasing the script max runtime in php.ini, it didn't help.


Here the function

public function indexAllMails($startIndex=1) {

$this->_imap = new Zend_Mail_Protocol_Imap('imap.gmail.com', '993', true);
$authenticateParams = array('XOAUTH', $initClientRequestEncoded);
$this->_imap->requestAndResponse('AUTHENTICATE', $authenticateParams);

//Create the mail storage Object
$this->_storage = new Zend_Mail_Storage_Imap_Wrapper($this->_imap);

//Select Folder
$this->_storage->selectFolder("[Gmail]/All Mail");


$numMessagesTotal = $this->_storage->countMessages();
if($numMessagesTotal == 0 ) return true;

for($i=$startIndex;$i<=$numMessagesTotal;$i++)
{
  try {
    $uniqueId = $this->_storage->getUniqueId($i);
    $message = $this->_storage->getMessage($i);
  }
  catch(Exception $ex)
  {
      log("Error getting Unique id",'index');
      log($ex->getMessage(),'index');
      log($ex->getTraceAsString(),'index');

      if($ex->getMessage() == 'cannot read - connection closed?')
      {
          //Timeout :(
          return true;
      }
      else
        continue;
  }

  $from = $message->from;
  echo $from;
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜