thinkphp静态缓存和纯静态有哪些区别?
最近写了个小程序,采用thinkphp
自己手动写了生成静态html模块,有后台批量手动生成。
后来发现,tp框架有静态缓存功能,也就是缓存之后php通过路径去读取真实html文件。
请问这两走方法有哪些优点和缺点呢?
回复内容:
最近写了个小程序,采用thinkphp
自己手动写了生成静态html模块,有后台批量手动生成。
后来发现,tp框架有静态缓存功能,也就是缓存之后php通过路径去读取真实html文件。
请问这两走方法有哪些优点和缺点呢?
两者有一个共同的目的,减少服务器的高并发处理和数据库负载的其中一个方法。
在国内呢,网站静态化还有一个目的就是为了“投搜索引擎所好”,从而能更好的SEO优化。(其实,我个人认为搜索引擎对静态或者动态页面并没有特别区分与偏好。控制好页面关键词效果都一样)。
你文中所描述的两者存储介质都是磁盘,前者“静态化”,其实没php什么事了,只是在服务器端这些文件都是由php控制生产而已,用户都是直接访问的静态页面。
而后者“文本缓存”的可控性更高。可定义缓存的过期时间,页面的局部缓存等等,从而更优的去控制内容更新等等。用户最后访问到的还是php动态页面,由php再去解释该怎么做,是直接读取file文件呢,还是缓存已经过期需要再重新生成下。
如果是大一点的站点,页面的大数据量对磁盘的消耗和维护也是很头疼的。
另外
我没有用过Thinkphp,但是按照我了解的一些php框架来看。基本上都会提供不少缓存适配器的驱动。
可以替换成更优的方案,比如:
使用memcached(内存对象缓存)。这其实与文本缓存过程类似,只是存储介质换成内存。读取速度当然更快。
再比如Alternative PHP Cache、Xcache、eAccelerator等等,这类缓存方案可以叫做php加速器。不同于上面所说的 文件存储和memcached内存对象存储。具体的可以看这里哪种php加速器最靠谱APC,XCache,eAccelerator,文中的几个外链可以点过去看看。其中有一篇介绍了他们的类似执行流程。
我推荐使用缓存方案。 网站的静态化处理个人感觉蛮“丑陋”的。
其实我后面说的缓存,有点偏离你说的“tp框架有静态缓存功能”。你这里说应用可能是tp提供的一个输出缓存也就是将页面视图进行一个整块文件存储,它帮你做了更细致的文件生成控制,比如生成为html后缀的文件。你可以再细致的看看tp的手册,特别的看看缓存的部分。
缓存要好些.
1.缓存是访问即生成.
2.静态是不论是否访问, 都需要提前生成. 以后维护模版很难. 更新数据量很大的时候,要费很长时间.
缓存是保存在内存里,静态是保存在硬盘里的HTML文件
速度来讲,缓存是比静态要快的。
缓存能更及时,至于哪个好,还是得看你服务器的内存情况了,如果内存小,那还是要酌情考虑要放到缓存里。
不清楚thinkphp的缓存具体实现,但是从你的描述,『PHP代码读取真实HTML文件』效率上是有问题的。应该由webserver来处理这部分读取,而不用PHP代码参与
推荐Google一下x-sendfile

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.
