search
Homephp教程php手册PHP中常用三种缓存技术

PHP中常用三种缓存技术

Jun 13, 2016 am 09:56 AM
cachephppointCommonly usedItechnologyWaymechanismofat presentcache

我是把目前php的Cache分成了这四种机制,第一种方式,需要加载模块,可能是收费的比如ZEND公司的,可能是免费的,不过多讨论;第二种方式,比如在成熟的大的站点上用比较合适;第三种方式和第四种四目前PHP业内程序中比较流行的方式

分成3个类别

1.缓存模块
这这个是在服务器上做的缓存设置,比如Zend公司的Cache产品等,主要原理是通过对PHP代码文件的一次编译保存在内存中,通过减少I/O的操作来加快访问速度,不在本文讨论范围之列
2.HTML方式
或许你说PHP生成HTML的方式不在本文讨论的范围之列,但是我个人人为这种方式仍然是一种Cache方式,如现在流行的生成HTML的程序也有不少,比如国内的一些CMS,这个也不在本文讨论的范围之列,一笔带过.
3.生成Cache文件
这个就是对一些常用的而且又不是经常变动的量,保存在文本中,通过减少mysql的查询量来加快程序执行,详细的内容我们随后介绍
4.php缓存机制
举个例子说,smarty模版里面的缓存机制,比如目前Discuz!论坛用的缓存机制,后面具体说

以Discuz!论坛软件5.0版本(或许你说了为什么以Discuz!为例,而不以PhpWind或者其实CMS为例,主要是因为Discuz!和我要说的后面两种缓存机制结合的比较好,而其他软件产品都或多或少的不太合适本文的要求)为例,在第三种机制中,Discuz!将基本设置和常用变量保存在forumdata/cache文件夹下面的一个文件中,比如cache_settings.php就是论坛设置的中的数据保存在一个数组总并存在这个文件中,在需要这些变量的时候就通过include这个文件来使用这些变量;在第四种机制中,Discuz!是把templates/default中的模版文件,预编译,也就是在请求访问index.php文件的时候,程序先在forumdata/templates中是否已经生成预编译的文件,如果存在则包含,如果没有则在模版文件夹中寻找模版然后生成,再包含,这么一个处理流程

在这种处理机制下,在小负载小站点的情况下,显然会有不少浪费,但是在中大站点或者说大型超大型站点的具体实施中,表现优异,但是显然做论坛的貌似都是负载比较大,国内水论坛一堆哇

再过来看Phpwind论坛,做为国内PHP论坛唯一能在Discuz!的压力下值得一提的一个论坛系统,显然在缓存机制上的处理不是很好,PW以前貌似也是做文本论坛起家的,同样的文本对于I/O的压力是很大的,尤其是在大中型站点的负载均衡上

写到这里突然不想写了,本来是想谢谢插件开发中的对于缓存和模版的应用,然后突然想到写一些我个人对于当前php缓存机制的一些理解,写到这里,写了2遍,狗日的服务器,娘的MYSQL老是丢失超时,你娘,服务器配的有点水平和好,靠,不写了

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment