Http://developer.51cto.com/art/200912/166975.htm
PHP file caching has always been a concern for PHP programmers, who have been exploring how to improve the efficiency of PHP file caching to meet their development needs
PHP file cache Content storage format is mainly three kinds:
1. Variable var_export formatted into PHP normal assignment writing format, when using the direct include file
2. Variable serialize is saved after serialization, and is deserialized when used
3, the variable json_encode after the format of the save, when used Json_decode
All along, I thought the first is the most efficient, because that is the PHP script interpreter parsing PHP script format, the original, should be the fastest, at least the efficiency of reading cache should be the highest, but today did a test, I am surprised! The original serialize serialization efficiency is the highest, whether it is read or write!
The following is the code used to test the PHP file cache:
<?php $st = microtime (1); for ($i =0; $i <1000; $i + +) { $file = Var_export ($_server,1); File_put_contents ("data/in.php", $file); } echo "Include write:". (Microtime (1)-$st). ""; $st = Microtime (1); for ($i =0; $i <1000; $i + +) { $file = file_put_contents ("data/se.php", Serialize ($_server)); } echo "Serialize wrote:". (Microtime (1)-$st). ""; $st = Microtime (1); for ($i =0; $i <1000; $i + +) { $file = file_get_contents ("data/se.php"); $file = Unserialize ($file); } echo "Serialize read:". (Microtime (1)-$st). ""; $st = Microtime (1); for ($i =0; $i <1000; $i + +) { $file = file_put_contents ("data/js.php", Json_encode ($_server)); } echo "JSON write:". (Microtime (1)-$st). ""; $st = Microtime (1); for ($i =0; $i <1000; $i + +) { $file = file_get_contents ("data/js.php"); $file = Json_decode ($file); } echo "JSON read:". (Microtime (1)-$st). ""; >
PHP File cache contains three formats