Page 1 of 1

sending a lot of emails at once

Posted: Fri Dec 02, 2005 10:22 am
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

Posted: Fri Dec 02, 2005 10:25 am
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;)

Posted: Fri Dec 02, 2005 10:35 am
by newmember
cron job - how do i use/access it? do all hosts have it available/enabled?

Posted: Fri Dec 02, 2005 10:38 am
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

Posted: Fri Dec 02, 2005 10:40 am
by newmember
ok thanks,
i will experiment with it...

by the way, are there any other situation where cron jobs are usefull?

Posted: Fri Dec 02, 2005 10:42 am
by Charles256
um. automated games they're the lifeblood:-D

Posted: Fri Dec 02, 2005 10:43 am
by Weirdan
cron is useful everywhere you need repetetive tasks running in background.

Posted: Fri Dec 02, 2005 10:49 am
by Ree
Actually I am also having the same problem. Is cron the only way?

Posted: Fri Dec 02, 2005 10:58 am
by newmember
do windows platform with php can have cron analogy?

Posted: Fri Dec 02, 2005 11:38 am
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

Posted: Fri Dec 02, 2005 12:10 pm
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.

Posted: Fri Dec 02, 2005 12:20 pm
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..)