2012-09-07 225 views
3

我正在使用imap_search从我的INBOX中获取消息列表。我只想要从地址发送的电子邮件,可以说“[email protected]”。Imap_search非常慢

我在做这样的:

$headers = imap_search($box,'FROM "[email protected]"', SE_UID);

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

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

+0

如果可能的话,请发表您的imap_search()调用进行的IMAP命令。 – arnt

回答

0

该方法已在过去超过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 == '[email protected]') 
    { 
    // you found one so do something 
    } 
}