开发者

How to : executing a block of code every 24 hours in a server?

I want to fetch certain data from website every 24 hours. The code must be executed every 24 hours and update the MySQL database. How can I accomplish this without any user events?

Later i'll use same data to开发者_开发技巧 find the total difference.

totalIncrement = currentData - earlierData

While earlierData is fetched from the MySQl database and current data is fetched from the external website query.

I've heard of a cron on linux but have never tried it. Can any body just give a basic idea for that? or any reliable link?

May be i want to do it like this::

First create a PHP program/file that does the fetching job. Second execute that PHP file every 24 hours or so...


Open a shell.
(Stop crond service service crond stop)
Use vi (or other editor) to edit cron file or type "crontab -e" to make your edit.
After edit hit "ESC". Then ":wq", to save and quit.
(Start the service again service crond start)
Stopping and starting the service is not needed if you use crontab -e.

Your script should be running by now. Check the syntax here or here. To view the changes you've made type "crontab -l".

I hope this helps.


It's safe to ignore the advice to start and stop the cron daemon when editing a crontab(5). The crontab(1) utility notifies the cron daemon that the crontab(5) file needs to be reread and changes will take affect immediately. The only reason you would ever need to restart the cron daemon is if you edited the crontab(5) file directly without the crontab(1) utility.


First you will have to make a php file for this example cron.php

So whenever you go to this link www.yourdomain.com/crom.php the script is executed

Now add this link in cron job. To set up cron job on your server you can us this class of php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜