Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php mail queue algorithm

Options
  • 27-07-2009 2:20am
    #1
    Registered Users Posts: 8,070 ✭✭✭


    Need few suggestions, right now i have

    -Something adding emails to table in database
    -script , running on regular intervals reading emails and sending the emails, then flagging them as sent so they are not read again

    -is there anyway i can run this in batches , i.e lets say i limit the results to 50, how do i run the script again ? or reiterate ? without running the cron job several times a day


    do i just put everything into a function and call the function again, recursive method type? until all emails are gone? that doesnt make a difference though does it ?

    i guess problem is script timing out, i could just set time limit to 0 ? or to avoid any errors i could use recursive method and close the sql connection after each iteration ?

    bit lost.


    Thanks


Comments

  • Closed Accounts Posts: 1,200 ✭✭✭louie


    have a look into sleep() php function.


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    the duration of sleep() is ignored in the execution time


  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    how about set up the page so it does a thousand at a time specified by $_GET variables, when it gets through the first thousand (script.php?start=0&finish=1000) it automatically reloads the page (script.php?start=1001&finish=2000) using header(location)?


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    There are a number of things you can do, but first question is how the script is being called. Are you invoking a URL call from cron or are you calling the script directly using the command-line interpreter?

    Check out this function:
    http://us2.php.net/manual/en/function.set-time-limit.php

    Use with care. On Unix systems, you could theoretically create a PHP script which will never die unless someone spots it and ends it. So if you don't account for cases where the script could stall, you could create issues for the server it's running on.


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    running it using lynx -dump, from the command interpreter

    i've set max execution time to 5minutes and set limit to 500 emails, reckon i could get away with 1k within 5min? its only html emails. But mail() is supposedly slow.

    BastardPrince, interesting but think i might just have cron execute few times a day for the first few days of the campaign


  • Advertisement
  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Totally going from an old memory here, but there are some mail systems (perhaps sendmail) which you can instruct to monitor a directory for files. Within those files is the email (including headers and the like). You could easily write 1k files to a directory in five minutes.

    The benefits and pitfalls are obvious, but it does take responsibility for sending the mails out of PHP's hands.


Advertisement