[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 645
  • Last Modified:

How to refresh database cached data?

Hi,

I am loading information form a database and caching the data with this script:
http://developer.yahoo.com/php/howto-cacheRestPhp.html

I them run the website of the cache instead of queering the server everytime.

What I want to do is have this data refresh a few times a day regardless if a user shows up or not. Currently the cache will only reload if a user goes to a page where the data is used and if the data is over 2 hours old. I feel cron might work here but don't know how to call a web page without a user going to it... or if that's even proper. Any ideas?

Thanks,
waffe
0
waffe
Asked:
waffe
  • 5
  • 4
3 Solutions
 
giltjrCommented:
Why do you want to waist resources refreshing the data?

Why do you care if the data is a few hours old, or even a few days old.  If it is refreshed when a user goes there, they are going to get the most recent data.

Think about it.  Lets say you refresh the data every 5 minutes, and for some weird reason nobody goes to that page for say 24 hours.  That means you are going to refresh something 288 times that nobody is going to see.

However, if you really want to you sould be able to use wget.
0
 
leakim971PluritechnicianCommented:
Hello waffe,

You can execute php script from shell and cron them. For example : http://www.htmlcenter.com/blog/running-php-scripts-with-cron/
http://www.php.net/manual/en/features.commandline.php

Regards.
0
 
waffeAuthor Commented:
giltjr:
My thoughts are that if a single page holds the key to the entire site being updated and no one goes to that page then data on other pages that users could go to will never get updated.

But your right, I could easily make the refresh 1 a week. The only problem with that is when the owner updates that database the cached data (live web site) would not updated for up to a week.

Thanks,
waffe
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
giltjrCommented:
I'm confused.  You are now saying there is a single page that causes the whole site to be updated.  Whereas in your original post you stated the data on a page would be updated whenever somebody went to that page.

So which is it, a single page that causes all data to be refreshed, or each page causes a refresh for the data displayed on that page?

If it is a single page that updates everything, the I would suggest some changes.

How old would you accept the data to be: 5 minutes, 10 minutes, 1 hour or something else?
0
 
waffeAuthor Commented:
It's a single page that causes all data to be refreshed.

The data could be up to 6 hours old, but thinking about it more I could create a page that the owner goes to after they update the database that refreshes the data. That way the cache is only updated when it's actually needed.

Thanks,
waffe
0
 
giltjrCommented:
Well, there are a couple of options.  

You change the site so that each page executes a PHP script that checks to see when the data was last refreshed.  If it has not been refreshed in the last "x" minutes, then it triggers a refresh.

Another option is that you modify the application that updates the data so that it will trigger the refresh when the user is done modifying the data.
0
 
waffeAuthor Commented:
"You change the site so that each page executes a PHP"
That's basically in the first link that I posted, the problem is the data I'm using is not on just on one page so there might as well be a master database for all the pages.

"modify the application that updates the data" - that would be great but the application is not in my control.

I'm going to go with a page that the owner goes to after they update the database; that will in turn, update the cache. I may also use a cron setup that will execute a php file as leakim971: mentioned and set it to once a month / week.  ]

Thanks,
waffe
0
 
giltjrCommented:
--> ... I'm using is not on just on one page ....

Maybe I'm missing something, but why can all pages be updated to trigger a refresh?

Is there any reason that you don't just read the database directly so you can get rid of the caching issue?
0
 
waffeAuthor Commented:
To ask the server if the data has been updated is not an option because I do not have control over the server. So there is know to ask the server if the data has been changed. With the cache link I posted the queried data is put into the cache with a timer that will trigger after a set amount of time and then someone comes to the page.

I do not  just read from the database because the company I am working with asked me not to and pointed me to the cache link above. And second, I have to re-order the data in such a way that will work better with website design.
0
 
giltjrCommented:
Thanks for the points.

Just to clear something up, I did not mean to ask the server, what I meant was that the PHP scripts that does the refresh as some code added that sets a variable (say lastrefresh) to the time of the last refresh.  When the script starts is checks this variable and if the current time is more than "x" minutes from the last time, then it actually does the refresh, if it is less than "x" minutes, it does not do the refresh.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now