【问题标题】:Imap_search very slowImap_search 很慢
【发布时间】:2012-09-07 15:10:25
【问题描述】:

我正在使用 imap_search 从我的收件箱中获取邮件列表。我只想要从该地址发送的电子邮件,比如说“somemail@gmail.com”。

我正在这样做:

$headers = imap_search($box,'FROM "somemail@gmail.com"', SE_UID);

但这需要很长时间,大约 3 分钟,收件箱只有 700 封电子邮件(我的邮箱是 GMAIL)。问题不在于服务器,因为我在 localhost 中安装了 roundcube 并快速加载电子邮件。

我该怎么做才能让它更快?

【问题讨论】:

  • 如果可能,请发布您的 imap_search() 调用执行的 IMAP 命令。

标签: php search imap


【解决方案1】:

过去对我来说,这种方法比 imap_search 工作得更快:

$stream = imap_open($mailbox,$username,$password);

//imap_num_msg returns the number of messages in the current mailbox, as an integer, so ..
$total_messages = imap_num_msg($stream);

for ($message_number = 0; $message_number < $total_messages; $message_number++)
{
  //get header
  $header = imap_header($stream, $message_number);

  if ($header === NULL)
  continue;

  //check from
  if($header->from == 'somemail@gmail.com')
  {
    // you found one so do something
  }
}

【讨论】:

    猜你喜欢
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 2011-03-08
    • 2013-02-23
    • 2015-12-24
    • 2020-10-23
    相关资源
    最近更新 更多