tags:

views:

100

answers:

7

i have a database in My-sql which have entries of time there are more than 1000 entries of time . i want to extract time and run a php script exactly at that time..

i have tried to run a php script continuously which check the time but my server does not allow to run script more than 60 seconds

EDIT I have to check the db every second is there any alternate .

+3  A: 

Try Unix's cron.

Pierre-Antoine LaFayette
+3  A: 

You'll need some external service to execute the script. On a Unix box, that would be cron. On a Windows box, use Task Scheduler.

Thomas
+1  A: 

Have you thought about writing your process as a server daemon. It would start up and run in a while loop forever. Every few minutes or however often you'd like it could check the next x minutes of run times. You queue up your requests and whenever that time comes around you kick off the script you need to run. I don't think cron is what you'd want since you are trying to schedule future events at arbitrary times... And I'm sure it's what you are currently using to try and check the db every second.

yes exactly . I have to check the db every second.is there any alternate solution . because querying again and again will become very cumbersome.
nicky
Well you just check every X minutes for every time it needs to run within the next X minutes. So something like:select time from times where time < now() + interval 5 minutes;Run this every 5 minutes and build up a unique queue of times. Check that queue every few seconds or whatever granularity you need to kick off the process whenever it's time has elapsed and remove it from the queue.
Why do you need to query every second?
Andy
A: 

You must must use the sleep(arg) function that pauses the php script for a given time and then continues.

sleep(50); //Pauses

myFunction(); //Runs after the pause

For example this pauses the script for 50 seconds.

Jonathan Czitkovics
A: 

Write a PHP script to read from the database and add entries to your crontab to make the script run at the desired time

nick
A: 

Keeping a process running is not a very good solution, not least because you'll need to ensure it does keep running. Presumably you know when the next occurrence is going to happen - so use the 'atd' to schedule it - when triggered the script should also work when and how to schedule the next job.

This does mean that jobs are chained - and failure of one breaks the chain, also the granularity of most implementations of atd can be rather high.

You might want to look at using a more sophisticated scheduling tool like Nagios or a process monitoring type approach like DJB's daemontools or Oracle's OPMN.

C.

symcbean
+1  A: 

Use the pear package, System_Daemon

http://pear.php.net/package/System_Daemon/

Dirty Frenchman
+1 System_Daemon. AWesome PEAR package, I use it with Gearman Workers
Urda