Home > Backend Development > PHP Tutorial > Performance Testing of PHP File Cache_PHP Tutorial

Performance Testing of PHP File Cache_PHP Tutorial

WBOY
Release: 2016-07-21 15:38:47
Original
720 people have browsed it

Common caching methods for PHP :
The first is to process the data that needs to be cached and form a file that PHP can directly execute. When you need to cache data, introduce it through include and use it.
Second, serialize the required data through the serialize function and save it directly to the file. When you need to use cached data, read the file content through deserialization and copy it to the required variables, and then use it.

Test results:
Through testing we found that the second way of caching data via serialize is more efficient. (The data is omitted, and the article address is provided for download at the end. You can test it yourself)

Cause analysis:
When reading the cache in include mode, PHP needs to perform several processes
1. Read the file
2. Parse the included file
3. Execute and assign values ​​to variables

When reading the cache in serialize mode:
1. Read data
2. Deserialize data content
3.Assign values ​​to variables

Summary analysis:
The first, include caching method
Advantages: Increase the confidentiality and security of data, and the cached content will not be discovered by the outside world.
Disadvantages: Relatively slow.
Purpose: Save data that is prohibited from being known outside the system, such as web system settings and even MySQL information

Second, serialize cache method
Advantages: faster.
Disadvantage: Once the cache system file path is exposed, the cache content will be leaked.
Purpose: You can use this method when caching the latest articles, related articles, etc., when you don’t worry about externally obtained data.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321700.htmlTechArticle Common caching methods for PHP: The first one is to process the data that needs to be cached to form a file that can be directly executed by PHP . When you need to cache data, introduce it through include and use...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template