PHP Server side time triggered action

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
kabuki1985
Forum Commoner
Posts: 32
Joined: Thu Jun 15, 2006 10:19 pm

PHP Server side time triggered action

Post 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
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

PHP is not the best tool for this. Use Crontab to execute your script at the desired time.
kabuki1985
Forum Commoner
Posts: 32
Joined: Thu Jun 15, 2006 10:19 pm

Post 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?
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post 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.
kabuki1985
Forum Commoner
Posts: 32
Joined: Thu Jun 15, 2006 10:19 pm

Post 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 ?
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

Next to none. Much less overhead than having your script running permanently at any rate.
kabuki1985
Forum Commoner
Posts: 32
Joined: Thu Jun 15, 2006 10:19 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
kabuki1985
Forum Commoner
Posts: 32
Joined: Thu Jun 15, 2006 10:19 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why not use a local calendaring-like application that has time triggers for reminders?
kabuki1985
Forum Commoner
Posts: 32
Joined: Thu Jun 15, 2006 10:19 pm

Post by kabuki1985 »

I'll google some up but any recommendation?
kabuki1985
Forum Commoner
Posts: 32
Joined: Thu Jun 15, 2006 10:19 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I was referring to something like Mozilla's Sunbird or Microsoft's Outlook.
kabuki1985
Forum Commoner
Posts: 32
Joined: Thu Jun 15, 2006 10:19 pm

Post 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? :)
Post Reply