Speed up message downloading with php's imap_open

Posted on 2005-05-12
Last Modified: 2008-02-01

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!
Question by:ditkis
    LVL 7

    Expert Comment

    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!

    Author Comment

    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?
    LVL 7

    Accepted Solution

    Perhaps use search?

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now