Been a while since I needed some help...

    Date: 04/19/06 (PHP Community)    Keywords: php, database, sql

    ...and this is more of a "what's the best way to do this" question.

    I have a php script that's long and complicated. Essentially it does this (in number form, because it's easier to think that way):


    1. Queries an database DB1 for membership figures, based on an expiry date.
    2. Counts the number of rows found.
    3. For each row, the script:
      1. selects the first record from the table,
      2. stores the information in an array
      3. clears all records from a table in DB2
      4. loads the information from the array into the now-empty table in DB2.
      5. builds an email using PHPMailer using a single, never-changing email address
      6. passes the mail to a mail server for delivery. This mail server has the email address from the previous step loaded as a SQL distribution list, so it queries DB2 to get its information.
      7. Send an update query to DB1 to change the expiry date.
    4. At the end of all rows, the script again empties the table in DB2, so that no data is left that could cause problems later.


    Now, i've discovered that the script is faster than the mail server when it comes to SQL queries, and if I don't put in a usleep(); call in the script, the table will be emptied again by the time the mail server goes to check, which means the mail won't be delivered.

    I've set the max_execution_time to 60 seconds in php.ini and the usleep to 500000 (half a second), but I'm still not getting any more than 20-something emails sent before the script hits the max_execution_time. I plan on later setting up a cron job to hit the script at regular times (outside work hours, so the mail server is free for our particular mailouts).

    What's the best value for me to put into usleep to allow the mail server (MDaemon 7.0.1) to collect its information and then let the script go ahead as fast as possible -- you know, the most mail out in the shortest time possible?

    Just in case I've missed something, is there possible a better way to design this (for version 2)?

    Source: http://community.livejournal.com/php/441047.html

« Broken function || Sessions »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home