Page 1 of 1
PHP Server side time triggered action
Posted: Fri Jun 23, 2006 4:56 am
by kabuki1985
I want to trigger an action based on time. What is the best way to do it? The only way i think of based on my skill is using sleep to repeatly check state of an event before triggering an action. Is there any other way ? I'll do the reading, just need to know what to find for. Thanks
Posted: Fri Jun 23, 2006 5:00 am
by jamiel
PHP is not the best tool for this. Use Crontab to execute your script at the desired time.
Posted: Fri Jun 23, 2006 5:07 am
by kabuki1985
Oh yeah, i need to communicate with MySQL as well. I will get the time and date values from MySQL and perform an action based on the database given. Will Crontab help?
Posted: Fri Jun 23, 2006 5:15 am
by jamiel
How specific is the time and date? I would make a cron job that runs my script every minute, and the first thing my script does is check the date and time, if they dont match then die else execute the rest of the script. That way you don't have to trust that your script isn't going to crash out.
Posted: Fri Jun 23, 2006 5:17 am
by kabuki1985
Perhaps accurate in minutes will do. I can create a php script which will check for event in MySQL on a minute to minute basis perhaps ? Will crontab produce overhead ?
Posted: Fri Jun 23, 2006 5:19 am
by jamiel
Next to none. Much less overhead than having your script running permanently at any rate.
Posted: Fri Jun 23, 2006 5:22 am
by kabuki1985
Okay, i'll give it a shot. I'm still open to any other programming language alternative if anyone has some idea. Thanks jamiel.
Posted: Fri Jun 23, 2006 10:15 am
by feyd
What sort of action are you wanting it to do? The reason I ask is because many actions that people want to do in "timely" manors are viewer dependant; they need to be seen to have any use. In which case, it can, most often, be done based on someone interacting with the server.
Posted: Sat Jun 24, 2006 6:53 am
by kabuki1985
What i have now
1. set a date and time
2. set an event
3. phpscript queries database on a minute to minute basis, i query base on day followed by time
3. perform the event matching time and date
Say i set an event in my database based on a calender reminder that i'm suppose to send my friend a file at some date and time. Or maybe send an email for a non-responsive action. The server side will automatically trigger this action. That is what i'm trying to do. But i don't want to incur too much overhead looping and looping to check for matching criteria in my database on a minute to minute basis.
Posted: Sat Jun 24, 2006 9:29 am
by feyd
Why not use a local calendaring-like application that has time triggers for reminders?
Posted: Sat Jun 24, 2006 10:09 am
by kabuki1985
I'll google some up but any recommendation?
Posted: Sat Jun 24, 2006 4:44 pm
by kabuki1985
There are php calendar codes but none of them are able to trigger events. One of the trigger I am thinking of is to contact another web server to send information when time trigger.
Posted: Sat Jun 24, 2006 6:05 pm
by feyd
I was referring to something like Mozilla's Sunbird or Microsoft's Outlook.
Posted: Sun Jun 25, 2006 4:34 am
by kabuki1985
Oh, i wanted the time trigger system to be able to perform something programmable. I don't think outlook does that. Any other ideas?
