tags:

views:

42

answers:

2

Hi,

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 time 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?

A: 

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

Aif
A: 

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.

meagar