2012-09-07 221 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 
    } 
}