Script to cache text/JSON file locally every hour
I'd like to build a simple php script to cache remote JSON files every hour.
Ideally, I would like to call the cached version like this:
jsoncache.php?uri=http://api.crunchbase.开发者_开发知识库com/v/1/company/evernote.js
Does a script like this already exist? Can anyone help me with some example code?
Alternatively, is there a web service that does this?
Thanks!
Not sure if something like this already exists (although I'd be surprised if it didn't). You could pull the data in PHP and save it to disk while storing the URL, a timestamp and the filename in a DB. When you get a request, you would do something like SELECT filename, timestamp FROM CacheList WHERE URL= ?
(where ? = $_POST['url']
). If the timestamp + 3600 < time()
then just serve up the file you already have, otherwise re-download it, update the DB and serve up the new page.
精彩评论