imap_sort限制结果数? [英] imap_sort limit the number of results?

查看:76
本文介绍了imap_sort限制结果数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将PHP与IMAP一起使用。我需要从文件夹中检索20个最新电子邮件。我使用imap_sort按日期排序,但是问题是,对于一个有700封和更多电子邮件的大文件夹,它会花很多时间。

I am using PHP with IMAP. I need to retrieve the 20 most new emails from a folder. I user imap_sort to sort by date, but the problem is that for a large folder with 700 and more emails it takes ages.

有没有一种方法可以使用PHP IMAP可以按日期对邮件进行排序,并且仅携带最新的20封电子邮件?

Is there a way i can use PHP IMAP to sort messages by date and bring only the latest 20 emails?

也许要使用imap_search吗?

Maybe to use imap_search ?

这里是我的代码:

$start_from  = params::cleanDefault($_GET, 'start_from', 0);
$limit       = params::cleanDefault($_GET, 'limit', 20);
$sort_by     = params::cleanDefault($_GET, 'sort_by', 'SORTARRIVAL');

$emails = imap_sort($mbox, $sort_by, 1, SE_NOPREFETCH);
$emails = array_slice($emails, $start_from, $limit); 

谢谢。

推荐答案

没有直接的方法。

您已经在最小化PHP <$ c $底层c客户端库获取的数据。 c> imap _ * 函数通过排序 SORTARRIVAL 而不是 SORTDATE 。并且,尽管有 IMAP扩展,它允许调用者请求以下内容的子集: SORT 结果(例如前20个匹配),很少有IMAP服务器支持它,PHP无法使用它。

You're already minimizing the data being fetched by the c-client library underlying PHP's imap_* functions by sorting on SORTARRIVAL instead of SORTDATE. And, while there is an IMAP extension that allows a caller to request a subset of the SORT results (e.g. the first 20 hits), very few IMAP servers support it and PHP can't make use of it.

您可以尝试使用 imap_search 并要求从1天前开始收到邮件。如果点击次数不足,您可以重新搜索自2天前收到的邮件。等等。但这可能会使代码混乱,并且最终结果可能不会比您已经做的更快。

You could try using imap_search and asking for messages arrived since 1 day ago. If that's not enough hits, you could re-search for messages arrived since 2 days ago. And so on. But this can get messy to code, and it may not end up being any faster than what you're already doing.

这篇关于imap_sort限制结果数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆