PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 8th, 2008, 03:15 PM
redd38 redd38 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: College Station, TX
Posts: 96 redd38 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 5 m
Reputation Power: 6
Send a message via AIM to redd38
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?

Reply With Quote
  #2  
Old May 8th, 2008, 03:21 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Beware
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2006
Location: Texas, USA
Posts: 1,703 ManiacDan User rank is Captain (20000 - 30000 Reputation Level)ManiacDan User rank is Captain (20000 - 30000 Reputation Level)ManiacDan User rank is Captain (20000 - 30000 Reputation Level)ManiacDan User rank is Captain (20000 - 30000 Reputation Level)ManiacDan User rank is Captain (20000 - 30000 Reputation Level)ManiacDan User rank is Captain (20000 - 30000 Reputation Level)ManiacDan User rank is Captain (20000 - 30000 Reputation Level)ManiacDan User rank is Captain (20000 - 30000 Reputation Level)ManiacDan User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 4 h 34 m 53 sec
Reputation Power: 263
Make use of the sleep function.

-Dan
__________________
"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

Reply With Quote
  #3  
Old May 8th, 2008, 04:13 PM
simshaun's Avatar
simshaun simshaun is offline
<?= ':-)' ?>
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: North Carolina
Posts: 103 simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 5 h 16 m 44 sec
Reputation Power: 23
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.

Reply With Quote
  #4  
Old May 8th, 2008, 07:11 PM
redd38 redd38 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: College Station, TX
Posts: 96 redd38 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 5 m
Reputation Power: 6
Send a message via AIM to redd38
and doing that won't cause max execution time problem? (as in, the script won't just timeout after a few minutes?)

Reply With Quote
  #5  
Old May 8th, 2008, 07:16 PM
simshaun's Avatar
simshaun simshaun is offline
<?= ':-)' ?>
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: North Carolina
Posts: 103 simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level)simshaun User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 5 h 16 m 44 sec
Reputation Power: 23
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.

Reply With Quote
  #6  
Old May 9th, 2008, 01:53 AM
Catacaustic's Avatar
Catacaustic Catacaustic is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Location: A Land Down Under
Posts: 353 Catacaustic User rank is Sergeant Major (2000 - 5000 Reputation Level)Catacaustic User rank is Sergeant Major (2000 - 5000 Reputation Level)Catacaustic User rank is Sergeant Major (2000 - 5000 Reputation Level)Catacaustic User rank is Sergeant Major (2000 - 5000 Reputation Level)Catacaustic User rank is Sergeant Major (2000 - 5000 Reputation Level)Catacaustic User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 8 h 38 m 44 sec
Reputation Power: 47
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.

Reply With Quote
  #7  
Old May 9th, 2008, 02:53 AM
Jenkz Jenkz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 178 Jenkz User rank is Corporal (100 - 500 Reputation Level)Jenkz User rank is Corporal (100 - 500 Reputation Level)Jenkz User rank is Corporal (100 - 500 Reputation Level)Jenkz User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 13 h 26 m 2 sec
Reputation Power: 10
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.......

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Email throttling


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway