drpsrvu85668 2013-02-06 08:11
浏览 33
已采纳

用PHP缓存

This question was probably asked before, but I cannot decide yet on what I should use. I'm building a small API Wrapper and there are some methods that could use some caching of the data I get with that method.

The data is in JSON format. So while I was browsing I found a few solutions to store this data. One of them is APC, which seemed pretty neat and more like using localStorage on the client side. But then I found that this is an extension that doesn't come with PHP preinstalled, and for the latest versions of PHP there are some bugs ( the developers don't consider it stable ). I also had a hard time adding it to XAMPP so I can test it locally.

So I left it out and considered other options like creating files on the server. This also seemed like a pretty good idea until I discovered that when I create a folder, the chmod is 0755 which isn't very convenient. I first thought it was something I did, but then I read a post here saying something about Safe Mode, which doesn't allow me to create folders with 0777 mode. So I was looking for a solution and I found that using FTP would solve it. I tried the FTP thing and it worked just fine, just that I had a hard time implementing a way for the connection to remain opened until it timed out and don't overwrite the connection each time I called the method that connected to FTP and created the folder.

Another solution I heard about is Memcache if I'm not mistaken, but that seemed like an overhead.

So I'm a bit in doubt on what I should use for caching the data. If anyone has some pointers it would be appreciated :)

  • 写回答

3条回答 默认 最新

  • dongsi4547 2013-02-06 08:16
    关注

    Whatever you do, don't write your own caching solution. The kind of people that can do that, don't need to ask questions about it on SO.

    • Install APC. It will solve far more problems than it creates.
    • Use Memcache and/or Redis to cache objects - sessions, scores, whatever.
    • Use Varnish to cache HTML in front of the web server.

    I have worked on apps with >10,000 requests per second using a combination of APC, Redis, Memcache and Varnish. They are very, very good.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容