|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Email throttling
I've got an app with many users, I want to create a script that will email all the users but i want the emails to be sent out over the span of several hours. What's the best way to do this with PHP?
|
|
#2
|
||||
|
||||
|
__________________
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002 |
|
#3
|
||||
|
||||
|
He's correct.
Run PHP script in the background with a perpetual while() loop in it, sleeping for a few seconds at the end of each loop. This mimmicks cron’s behaviour. Each iteration of the loop might pull out 50-100 emails and send them. |
|
#4
|
|||
|
|||
|
and doing that won't cause max execution time problem? (as in, the script won't just timeout after a few minutes?)
|
|
#5
|
||||
|
||||
|
It might, I don't know without testing it.
Try it (just echo out a string every few seconds) and see if it halts after your server's max_execution_time. If it does, then write a .htaccess file to change that if your server supports it. .htaccess file contains: Code:
php_value max_execution_time "300" Where 300 is in seconds. |
|
#6
|
||||
|
||||
|
One of the best ways of dealing with this (assuming that your server supports this) is to run the email sending script as a CRON job and set it to send 50-100 or however many emails you want for each run. Then just add the new messages to a processing queue, and wait for them to send. You can set the CRON to run however frequently you want, and there's no issues with execution times.
|
|
#7
|
|||
|
|||
|
All emails from my site are added to a "mailQueue" table in MySQL.
They then get sent out in batches of 100 with a sleep(0.1) in the while loop from the db. The cron job runs every 5 minutes. This reduces any stress on the mail sending protocall for non-urgent emails....... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Email throttling |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|