• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

Speed up message downloading with php's imap_open

Hello,

I have an webmail application.
I'm using crontab to run php script to get messages from pop3 accounts and store it in user's DB. As I got many users crontab running time has become huge: 30-40 mins for 120 mailboxes. Is there a way to speed it up? May be there is a way to download only recent emails or anything else?

Please advise!
Thanks,
Yuri
0
ditkis
Asked:
ditkis
  • 2
1 Solution
 
PromethylCommented:
If you use UIDL you can get the unique IDs of the messages. As you build up your db, you can compare those to the the Unique iDs in your database, and only download those new messages. Beyond that...

This is all in theory btw...

for ($msgno=1;$msgno< imap_num_msg ( $imap_stream ); $msgno++) {
    $uid=  imap_uid ( $imap_stream, $msgno );
    // db query here
    $r=  mysql_query("select * from mail where uid = $uid limit 1;");
    if (!mysql_num_rows($r)) {
                // go get it boy!
    }
}
0
 
ditkisAuthor Commented:
I'm afraid, that's what I'm doing now.
Some of the users store A LOT of emails on server... Going through all of them every time IS my problem.
How can I aviod that?
0
 
PromethylCommented:
Perhaps use search?

http://us3.php.net/manual/en/function.imap-search.php

You could do  SINCE "date" - match messages with Date: after "date" and look only at messages from the last day?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now