Imap_search very slow

瘦欲@ 提交于 2019-12-13 13:18:03

问题


I'm using the imap_search to get a list of messages from my INBOX. I want only the emails sent from the address, lets say "somemail@gmail.com".

I'm doing like:

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

But this takes so many time, around 3 minutes and the inbox have only 700 emails (my box is GMAIL). The problem is not from the server, because i installed roundcube in the localhost and loads the emails quickly.

What can i do to make it faster?


回答1:


This method has worked faster than imap_search for me in the past:

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


来源:https://stackoverflow.com/questions/12320814/imap-search-very-slow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!