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 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line