On Sat, June 25, 2005 11:55 am, Arthur Wiebe said: > vlad georgescu wrote: >> i want to make a "reminder" application which sends emails at certain >> hour >> in php. is this posibile ? if not, what else can I use ? >> > > I've done it using pure PHP for a calendar script. > > What I did was write a PHP script with a loop that checks every second > whether or not something should be done. For example: > > > <?php > $t = true; > while ($t) { > if (time() == $myTimeStamp) { > mail(args); > } > } > ?> > > at the top of the script I have a line like this: > #!/usr/bin/env php > for *nixs' and I wrote a little batch file for Windows systems. > At least it works.
This works, but it's kind of resource intensive, I think... You've pretty much got a whole PHP binary running all day, every day. Not a real big deal, but it's not really needed, as you'll see. Your loop is the big issue. You're going to call time() maybe a few thousand times in one second! At least in *MY* single crude bench mark test, it got called 6082 times. <?php $start = time(); $i = 1; while (time() == $start){ echo $i, "\n"; $i++ } ?> I will spare you the 6000+ lines of output, but it ended with 6082. :-) Do you really want PHP sitting there spinning its wheels furiously to call time() 6000 times every second?... You could simple put a sleep(1) inside your loop, so it would sleep for one second. Even then, do you really need to check email every single second of every day? Maybe if you have a *TON* of email to send out... It's more likely that sending email every 5 minutes would work just fine. The better solution, IMHO, would be to use cron (see: man 5 crontab) to run a script every 5 minutes to see who needs to get email notification, and send out the emails, and quit. 5 minutes can be varied as needed for your application. Sometimes it can be 24 hours, or a whole week. Other times you actually *WANT* it every minute. If your web calendar only allows things to occur on even 15 minute blocks, then there's not much point to checking more frequently than every 15 minutes, because nothing can happen to change things until 15 minutes goes by, except users changing their preferences, and that can either run the script as well, or they can just be warned in the interface that it will take at least 30 minutes for their change to take effect. 29 minutes, actually, if they just missed the last cron job, but who's counting? -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php