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:
- View Plaincopy to Clipboardprint?
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- /*
- $ file = Var_export ($_server,1);
- $ file = "" ;
- File_put_contents ("data/in.php", $file);
- */
- Include ("data/in.php");
- }
- echo "include read:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- $ file = file_put_contents ("data/se.php"
- , serialize ($_server));
- //$ file = file_get_contents ("data/se.php");
- //$ file = unserialize ($file);
- }
- echo "Serialize wrote:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- //$ file = file_put_contents ("Data/se.
- PHP ", serialize ($_server));
- $ file = file_get_contents ("data/se.php");
- $ file = unserialize ($file);
- }
- echo "Serialize read:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- $ file = file_put_contents ("data/js.php
- ", Json_encode ($_server));
- //$ file = file_get_contents ("data/js.php");
- //$ file = Json_decode ($file);
- }
- echo "JSON write:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- //$ file = file_put_contents ("Data/js.
- PHP ", Json_encode ($_server));
- $ file = file_get_contents ("data/js.php");
- $ file = Json_decode ($file);
- }
- echo "JSON read:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- /*
- $ file = Var_export ($_server,1);
- $ file = "" ;
- File_put_contents ("data/in.php", $file);
- */
- Include ("data/in.php");
- }
- echo "include read:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- $ file = file_put_contents ("Data/se.
- PHP ", serialize ($_server));
- //$ file = file_get_contents ("data/se.php");
- //$ file = unserialize ($file);
- }
- echo "Serialize wrote:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- //$ file = file_put_contents ("Data/se.
- PHP ", serialize ($_server));
- $ file = file_get_contents ("data/se.php");
- $ file = unserialize ($file);
- }
- echo "Serialize read:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- $ file = file_put_contents ("Data/js.
- PHP ", Json_encode ($_server));
- //$ file = file_get_contents ("data/js.php");
- //$ file = Json_decode ($file);
- }
- echo "JSON write:". (Microtime (1)-$st). "";
- $ St = Microtime (1);
- For ($i=0; $i<$i + +) {
- //$ file = file_put_contents ("Data/js.
- PHP ", Json_encode ($_server));
- $ file = file_get_contents ("data/js.php");
- $ file = Json_decode ($file);
- }
- echo "JSON read:". (Microtime (1)-$st). "";
The result is amazing! Include write: 0.559882879257include read: 0.185745000839serialize write: 0.255033969879serialize read: 0.0853068828583json write: 0. 284864902496json read: 0.145938873291 serialization is the fastest, no matter read or write, is the first kind of efficiency of twice times, JSON than the serialized PHP file cache efficiency is slightly lower, performance is also possible!
If you put aside the time it takes to read and write, their efficiency may be more different! Include that, although is the PHP script assignment format, but also to parse the parsing text, the PHP script interpreter needs to use the entire interpreter to parse the PHP script, but the serialization does not need, only then enables the serialization text analysis to be OK, therefore the PHP file cache is more efficient.
http://www.bkjia.com/PHPjc/446094.html www.bkjia.com true http://www.bkjia.com/PHPjc/446094.html techarticle PHP File Cache Content storage format is mainly three kinds: 1. The variable var_export formatted as PHP normal assignment writing format, when used directly include file 2. Variable serialize after serialization ...