Zend Imap 连接超时

发布于 2024-09-27 08:56:29 字数 803 浏览 6 评论 0原文

我正在使用 Zend 框架提供的 IMAP 类通过 imap 访问 gmail 消息。我一一访问收件箱中所有邮件的邮件标题并在本地索引它们。对于消息少于 10000 条的收件箱,该脚本运行良好。对于较大的收件箱,脚本会断开连接,可能会超时。

这是堆栈跟踪:

异常消息:无法读取 - 连接已关闭?

跟踪:

#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 /home/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)

有没有可能的方法来保持连接更长时间?我通过命令行运行此脚本并尝试增加 php.ini 中的脚本最大运行时间,但没有帮助。

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 /home/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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末的微笑 2024-10-04 08:56:29

这里的函数

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

}

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

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文