Imap_search非常慢 [英] Imap_search very slow
问题描述
我正在使用imap_search从我的收件箱中获取消息列表.我只希望从该地址发送的电子邮件,比如说"somemail@gmail.com".
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".
我在做:
$headers = imap_search($box,'FROM "somemail@gmail.com"', SE_UID);
但这花费了很多时间,大约3分钟,收件箱中只有700封电子邮件(我的邮箱是GMAIL).问题不在于服务器,因为我在本地主机中安装了roundcube并快速加载了电子邮件.
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?
推荐答案
在过去,此方法对我来说比imap_search的运行速度更快:
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
}
}
这篇关于Imap_search非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!