Page 1 of 1

Server Load when Sending 1000 Emails at Once

Posted: Sun Feb 27, 2005 10:14 am
by zenabi
I am writing a script that will be automated to run once a day using a cron job. It will be similar to how job (recruitment) sites send emails to users every day based on their stored search criteria.

This is what I have worked out in my head so far:

At 1am every morning my script will (for every user in my database):
1. Run a SELECT COUNT query with the stored search criteria and a clause to search for jobs that were posted after the date that the previous email was sent. Eg. SELECT COUNT(*) FROM jobs WHERE location='London' AND post_date > $date_last_email_sent

2. If the count is greater than zero, then send an email to the user stating how many new jobs have been posted.

3. Update date_last_email_sent field with NOW().

Now if I have 1000 users in my database, this script will loop 1000 times and send 1000 emails (assuming all searches have matches).

What are the implications of this on a server? I'll only be using shared hosting. Would it be too heavy to run every day?

Is there a better way I can do this? I'd like to hear your thoughts.

Posted: Sun Feb 27, 2005 10:38 am
by Trenchant
Run it in sections. I would only send like 10 emails every 10 minutes.

So starting at 1:00 the server goes through and selects the first 10 people. It sends the emails and then updates a row saying those emails were sent. 10 minutes later it does the next 10 and so on.


You could probably get away with doing more than 10. Depends what type of server your webhost uses.

Posted: Sun Feb 27, 2005 10:55 am
by feyd
search the forums for "mass mail" we've only talked about it a couple times. :?

Moved to PHP - Code.

Posted: Sun Feb 27, 2005 12:33 pm
by Buddha443556
Web Dummy wrote:So starting at 1:00 the server goes through and selects the first 10 people. It sends the emails and then updates a row saying those emails were sent. 10 minutes later it does the next 10 and so on.
I think Web's 10 minute delay is a good conservative number for your typical oversold shared server. However, I have host that have said every 10 seconds and some have said not on my server you won't. You should really talk to your host to find the definitive answer for your server. Be sure to check your terms of service too.

Posted: Mon Feb 28, 2005 6:12 am
by zenabi
Thank you all for your help.

It seems the best way to do this is to use a delay method and not to use the mail() function (but use a method to close a socket connection after all the emails have been sent, as opposed to closing after each sent email).

I will investigate this further. Thanks again.