Showing statistics that refresh every 10 minutes

Associate
Joined
18 Nov 2008
Posts
2,430
Location
Liverpool
I'm sure you've all seen all the websites that have a stats page, and underneath they say "These stats refresh every 10 minutes".

Now I know why this is done - presumably to save such big querys being executed every time someone hits refresh - but my question is, how is it done?

Is it:
A: A timer is ran and every 10 minutes a function is ran to obtain the statistics and put them into a table which the site then reads from.

B: The last refresh time is stored, and when a user refreshes, if the data is more than 10 minutes old, it re-runs the query and then saves the data into the database, removing the need for a timer

C: Something else?

Hope this makes sense, thanks!

EDIT: P.S. Language is PHP!
 
I'm sure you've all seen all the websites that have a stats page, and underneath they say "These stats refresh every 10 minutes".

Now I know why this is done - presumably to save such big querys being executed every time someone hits refresh - but my question is, how is it done?

Is it:
A: A timer is ran and every 10 minutes a function is ran to obtain the statistics and put them into a table which the site then reads from.

B: The last refresh time is stored, and when a user refreshes, if the data is more than 10 minutes old, it re-runs the query and then saves the data into the database, removing the need for a timer

C: Something else?

Hope this makes sense, thanks!

EDIT: P.S. Language is PHP!

Ajax (basically javascript) that calls a php file which generates the stats. Then the php output from that file is reloaded every 10 mins in a div tag on the main page.
 
Set-up a cron to run a PHP file every 10 minutes and store the output somewhere, include that result in your website.
 
The way I've achieved this with a custom monitoring (for a custom app at work) portal, is there are some control scripts (written in Perl) which run every xx minutes, which update basic text stats files (XML).

Then the PHP web pages are coded to read those xml files, and can refresh whenever they like.

I've actually got a custom scheduler that can be controlled via an admin interface, so that an admin can login and adjust what gets updated and when, and then a central engine (also written in Perl) which manages the scheduler. It's just a nice-interfaced custom version of cron tbh.
 
It could be done simply using the JavaScript setTimeout function along with window.location.href.
 
Back
Top Bottom