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

Performance Testing of PHP File Cache_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:36:31872browse

Foreword:
In the process of developing MooPHP, in order to find a more efficient caching method, the two most commonly used caching methods were tested.

Common caching methods for PHP:
The first one 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 method 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 give variables Assignment

When serializing the cache to read:
1. Read the data
2. Deserialize the data content
3. Assign a value to the variable

From the comparison of the above content, it may be because the time required to parse the array in the PHP file exceeds the time required to unserialize the array. If you are interested, you can check out "Research on Performance Efficiency of PHP filesystem related functions and include require": html">http://www.ccvita.com/163.html

Test file code:
Download address: MooPHP-CacheTest.zip
Original address: http://www.ccvita.com/311.html New research experience will be updated here.
CacheTest_IncludeFile.php
CacheTest_SerializeFile.php

Summary analysis:
The first method, include caching
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, the serialize cache method
Advantages: Faster speed.
Disadvantages: The cache system file path is exposed at one point, and 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.

Remarks:
When PHP memory caches such as ea and apc are installed, the first method of reading the cache through include will be faster than the second method of serializing the cache. Therefore, in the MooPHP framework, we cache non-sensitive information in the second way; sensitive information is cached in the first way. For an introduction to MooPHP, please refer to the article "Introduction to MooPHP Framework" (Address: http://www.ccvita.com/295.html)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508213.htmlTechArticlePreface: In the process of developing MooPHP, in order to find a more efficient caching method, the two most commonly used Caching methods were tested. Commonly used caching methods in PHP: The first one is to cache the needs...
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