sending a lot of emails at once

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

sending a lot of emails at once

Post by newmember »

Hi,

I want to send weekly emails to few thouthands users who are students..(lessons schedule + some additional info)
each email message might be as large as ~3mg(in some cases there will be an attachements in form of images).

Say,i use mail() function in loop. There are going to be a few thouthands of iterations. during each iteration there is some work to be done for generating email... it takes time...

I have doubts if it is a proper approach in this case :?
it seems to me that such a script will be simply timed out...(max_execution_time) or system at some point will deny any additional requests...


What do you think is the proper way to handle such situation?
thanks
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

hum......maybe not the most efficient way but off the top of my head...say on the first call of the page count the rows and store how many rows there are in a field somewhere.then do the first twenty.on each call after that check where you are and where you need to be. do 20 each call of the page until you get to the number you need to be at then set a flag saying your done for that week (in the database obviously).of course you'll need to check for that flag each loop before starting anything.and then have a cron job call the page every fifteen minutes or so(maybe less?). and to make the coup de grace when it's finished (the flag exists) have it e-mailing you telling you to go delete the cron job :-D i dunno..that's just off the top of my head:-D

edit: if anyone has a better idea please feel free to laugh at me as you explain a better way;)
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

cron job - how do i use/access it? do all hosts have it available/enabled?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

all that I have seen have it enabled:-D just ask your host wher eit is if you can't seem to locate it on your cpanel/vdeck
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

ok thanks,
i will experiment with it...

by the way, are there any other situation where cron jobs are usefull?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

um. automated games they're the lifeblood:-D
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

cron is useful everywhere you need repetetive tasks running in background.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Actually I am also having the same problem. Is cron the only way?
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

do windows platform with php can have cron analogy?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

windows scheduler?

youd have to make the scheduled task run a batch file that contains the path to php

Code: Select all

C:/php/php.exe script.php
or something, I don't know haven't used windows batch files in ages

Edit: I see it in control panel - scheduled tasks on my winxp computer
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

i used a cron job when taking over 2000 requests off of a server to build a advertising database/website. if i had just looped the whole thing i would have gotten banned but when i just made 4 requests every 5 minutes it worked fine.

recently i used a cron job every day at 12 to change a "expired" account to a guest account and send the user a email to notify them.

cron jobs are ultra useful.
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Post by trukfixer »

could check out phpmyemaillist ( I think) or phpmailinglist or something by a similar name at sourceforge.net .. I havent worked on it in a *LONG* time, however when I got involved with it, I took the code and adapted it to run on a cron, which it then sent our to a mailing list of over 35,000 over a 12 hour period (and if you use phpmailer class, you can also load balance by sending email "jobs" to multiple smtp servers, easing the overall load..)
Post Reply