Php file cache performance test. Read the php file cache performance test, the two most common cache methods are tested. Common cache methods for PHP: first, process the data to be cached to form a file that can be directly executed by PHP. When data needs to be cached, connect to "> <LINKhref =" http: // www. php1
Preface:
During the development of MooPHP, in order to find a more efficient cache method, the two most common cache methods were tested.
Common PHP Cache methods:
First, process the data to be cached to form a file that can be directly executed by PHP. When data needs to be cached, it is introduced and used in the include mode.
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, copy the content to the required variable, and then use it.
Test results:
Through tests, we found that the second method, namely serialize, caches data more efficiently. (The data is omitted, and finally the article address is provided for download. you can test it on your own)
Cause analysis:
When reading the cache using the include method, PHP needs to execute several processes.
1. read files
2. parse the included files
3. execute and assign values to variables
When serialize is used to read the cache:
1. read data
2. deserialize data content
3. assign values to variables
Compared with the above content, it may be because the time required to parse the array in the PHP file exceeds the time of the unserialize deserialization array. If you are interested, you can view the PHP filesystem related functions and include require performance efficiency research: http://www.ccvita.com/163.html
Test file code:
: MooPHP-CacheTest.zip
Original address: http://www.ccvita.com/311.htmlnew research will be updated here.
CacheTest_IncludeFile.php
CacheTest_SerializeFile.php
Summary:
First, the include cache method
Advantage: it increases data confidentiality and security, and the cached content will not be discovered by the outside world.
Disadvantage: the speed is relatively slow.
Purpose: Save data that is not known outside the system, such as web system settings and even MySQL information.
Second, serialize serialization cache method
Advantage: fast.
Disadvantage: the file path of the cache system is exposed, and the cached content is exposed.
Purpose: This method can be used to cache the latest articles and related articles without worrying about external data.
Note:
When PHP memory caches such as ea and apc are installed, the first method of reading the cache through include is faster than the second method of serialize serialization cache. Therefore, in the MooPHP framework, we use the second method to cache non-sensitive information, and the first method to cache sensitive information. For more information about MooPHP, see the introduction to the MooPHP framework in this article (address: http://www.ccvita.com/295.html)