开发者

How to schedule in php

I have some files on my server, how to open them programatically once a 开发者_如何学Goday?

Let them be

http://site.com/scripts/video.php
http://site.com/scripts/music.php

Without my hands, just like sheduling (automatically).

Even if I sleep and server is working, they should open on given time.

And additionally, how to open them once a 10 seconds (for tests)?

Thanks.


The Solution is very clear when you are using a Linux server;CRON JOBS. One can easily run a cron job by configuring it through the terminal.I saw everyone has provided the Solution,but my answer will be for the people who are novice to Linux servers and don't know much about Cron Jobs.Go to Terminal and type the below commands..

root>which php

The above line will give you the path to where PHP is in your linux systems Now,

root>crontab e

The above line will open the Cron file in edit mode. Enter the number of times you want to run a particular php file and what time of the day,month,week,etc. I am providing the syntex for running a particular file every 15 mins. So here you go,

(write this in the cron file in edit mode)

*/15 * * * * path/to/your/php path/to/the/file/you/want/to/run

Now,path/to/your/php has to be replaced by the path what you got when you typed

root>which php

And you are done just save the file and close it.You will see a messege on you terminal that a new CronJob is installed. That's it.


If you're on a Linux/Unix host using a cron job is generally the best approach, as you can simply call the command line version of PHP as a part of the cron job. (You may need to tweak your script if it relies on $_SERVER variables, that said.)

Administration middleware (such as Plesk) often offer the ability to add cron tasks as well, although you many need to check the user/group rights that such tasks are executed with.

Finally, if you use a cron task you can simply enter the required command via the command line during the testing phase. (i.e.: Rather than force a 10 second update (which would be tricky unless you had cron execute a shell script) you could execute the script as required.)


It's not possible with pure PHP. You'll need a cron job for this - ask your provider or administrator whether they are available.

Cron has a resolution of 1 minute, though: Calling a script once every 10 seconds would have to be done e.g. using a PHP script that gets called every minute, and makes six requests every ten seconds.


Running them once a day requires a seperate program running them.

For linux servers the usual choice is a Cron Job, for Windows the Task Sheduler works fine, too.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜