开发者

Execute PHP files periodicaly

The question is very easy, I want to execute several php files every "N" minutes. For example:

every N minutes { execute(script1.php) execute(script2.php) execute(script3.php) }

I know abou开发者_如何学运维t crontab but i was trying to find another solution. Any suggestions? Thanks in advance.


Using a Cron job is the usual solution. Can you explain why you don't want to use CRON? I've also seen libraries that add cron-like features to your system. For example in the Java/Groovy/Grails world there's the Quartz library/plugin. A quick Google search yielded a PHP library called phpJobScheduler that seems similar to Quartz. I have never used phpJobScheduler so I can't vouch for it.

I'd be interested in why you don't want to use crontabs for this? Are you going to be the primary web operations person running this server or will you be relying on an existing sysop team? You may want to get their input since they are the ones who will be most impacted by what method you choose. I've found they tend to be fond of cron for simple scheduling.


On windows I used built-in proggie called Task Scheduler. As for linux, yes, cron jobs is your answer.


You could create a php script to loop forever do X every N minutes and run the command with a & to make it a background process.

/path/to/php /home/user/bgscript.php &

If you want it to always run, you'd then have to add it to startup init.d or services depending on flavor of *nix.

This solution is possible but personally I would highly recommend going with crontab, its established, proven and works well! Why are you avoiding it?


You could build a script and let it run as a daemon and perform certain tasks on a set interval, but that's actually just simulating cron ... and if you have the ability to run a php script as a daemon you should really also be able to run it as a cronjob since that's what crons are made for.

If you need more info on how to run a php script as a daemon read this great intro. There is also a great comparison between daemon and cron inthere, worth the read.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜