开发者

PHP Update Entry Every Hour

I'm working on a site that generates a dynamic image based on data from another site. The problem is that loading the data from the other site ever t开发者_运维知识库ime the image is accessed is slow. The Image displays the current stats of a "team" on a tournament website. I want to make a cron job and database that work together to update the info on a specific "team" every hour from when the team was last updated. For example, I could have the following db field:

ID, Name, Url, Wins, Losses, Xp, DateLastUpdated

So with my cron job, I want to update the entries every time the current date is an hour from the date last updated. How should I do this? Is there a specific way I should store the date and time? Should I even use a date and how often should I run the cron job?


If you have a unix system, place a file in /etc/cron.hourly/myjob containing something like:

#!/bin/bash

php /path/to/script.php

or via crontab -e or any interface

01 * * * * php /path/to/sync-script.php

should do the job. It will run sync-script every hour:01


You don't need to store the last time the image was updated; you can simply set your cron job to run hourly. If the cron job is running once per hour and it's the only thing creating the image, you know that the image is exactly 1 hour old at the time your script is invoked.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜