开发者

Run PHP script continuously

开发者 https://www.devze.com 2022-12-22 12:23 出处:网络
I have a database in MySQL 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..开发者_如何学Python

I have a database in MySQL 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..

开发者_如何学Python

I have tried to run a PHP script continuously which check the time, but my server does not allow to run the script for more than 60 seconds.

EDIT. I have to check the database every second. Is there any alternative?


Use the pear package, System_Daemon

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


Try Unix's cron.


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.


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.


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


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.


You 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.


DJB's DAEMONTOOLS is great. So, apparently, is systemd and/or Upstart, though Remnant plays a true wanker.


The recommended Pear package - system_daemon looks great. However, the author now recommends to use new functionality that's readily available in Ubuntu: upstart

See his article on his own blog from 2012

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号