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.
Server Load when Sending 1000 Emails at Once
Moderator: General Moderators
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.
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.
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
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.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.