dpwfh874876 2011-08-04 21:23
浏览 25
已采纳

脚本每小时在本地缓存文本/ JSON文件

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!

  • 写回答

1条回答 默认 最新

  • doujiang1832 2011-08-04 22:06
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥30 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题