如何为PHP网站实现HTML缓存? [英] How do I implement a HTML cache for a PHP site?

查看:89
本文介绍了如何为PHP网站实现HTML缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实现PHP站点缓存的最佳方式是什么?很明显,有些东西不应该被缓存(例如搜索查询),但我想找到一个很好的解决方案,以确保我避免了'digg效应'。



我知道WordPress的WP-Cache,但我正在编写一个不是WP的自定义解决方案。我对写自己的缓存(如果它足够简单)感兴趣,或者你可以指向一个漂亮,轻量级的框架。我不太了解Apache,所以如果它是一个PHP框架,那么它会更好。



谢谢。


<如果代理缓存不存在问题,并且您提供的是完整的HTML文件,那么您将通过完全绕过PHP来获得最佳性能。研究 WP超级缓存的工作原理。

未缓存的网页会被复制到具有类似网址结构的缓存文件夹中作为您的网站。在稍后的请求中,mod_rewrite会记录缓存文件的存在并代替它。其他RewriteCond指令用于确保评论者/登录用户能够看到实时PHP请求,但大多数访问者将直接由Apache提供服务。


What is the best way of implementing a cache for a PHP site? Obviously, there are some things that shouldn't be cached (for example search queries), but I want to find a good solution that will make sure that I avoid the 'digg effect'.

I know there is WP-Cache for WordPress, but I'm writing a custom solution that isn't built on WP. I'm interested in either writing my own cache (if it's simple enough), or you could point me to a nice, light framework. I don't know much Apache though, so if it was a PHP framework then it would be a better fit.

Thanks.

解决方案

If a proxy cache is out of the question, and you're serving complete HTML files, you'll get the best performance by bypassing PHP altogether. Study how WP Super Cache works.

Uncached pages are copied to a cache folder with similar URL structure as your site. On later requests, mod_rewrite notes the existence of the cached file and serves it instead. other RewriteCond directives are used to make sure commenters/logged in users see live PHP requests, but the majority of visitors will be served by Apache directly.

这篇关于如何为PHP网站实现HTML缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆