Home >Backend Development >PHP Tutorial >Performance Testing of PHP File Cache_PHP Tutorial
Foreword: Common caching methods for PHP: Test results: Cause analysis: When serializing the cache to read: 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: Summary analysis: Remarks:
In the process of developing MooPHP, in order to find a more efficient caching method, the two most commonly used caching methods were tested.
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.
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)
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
1. Read the data
2. Deserialize the data content
3. Assign a value to the variable
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
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.
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)