PHP中常用三种缓存技术
我是把目前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老是丢失超时,你娘,服务器配的有点水平和好,靠,不写了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
