views:

36

answers:

1

What is the best way to send e-mails or perform functions on a small, non-real money auction script? This script is a learning exercise for me and I was wondering what the best way would be to process actions when the auction has expired. A cron job every minute seems - to me - a method which can easily be surpassed.

+4  A: 

To be honest, this is an ideal situation for a cronjob. Theoretically, you could create cronjobs on the fly...That is edit the crontab with php and create an entry for each auction with their end time to execute a generic script that has some variables passed to it.

A cronjob every minute seems a bit extreme, but if you space it out a bit the idea seems very reasonable.

Alternatives would be for if someone hits the auction page that the script checks to see if the auction is expired and then sends an email and sets a flag in a table column. This overall is a terrible idea (What if no one visits the page for a few days).

Ideally the cronjob is your best friend here. Now you can go with an hourly style cronjob or create a script that generates one time cronjobs on the fly. The best solution though would be a recurring cronjob (per 10 minutes perhaps?) and as it sends out an email for an auction, a flag is set in an column ie email_sent to 1 or something similar so that emails aren't resent erroneously.

CogitoErgoSum
Not sure what a "one time cronjob" is or what worth it has (ie., these are scheduled jobs that should run more than once), but I agree with the overall "use cron" message.
Sam Bisbee
Do the one time cronjobs delete themselves or would the script have to clear them as well?
jSherz
Creating a cronjob needs command line access (at least through shell_exec), and if you have that, you're better off using `at` instead of cron. That basically creates one-time cronjobs.
Maerlyn
A cron job per auction may not scale on high volume and since this is a learning exercise, you should consider how any proposed solution may scale. What if you had 10,000 auctions all ending at midnight? The recurring job (as described in CogitoErgoSum's last paragraph) is the way to go.
webbiedave