PHP file cache contains three formats

Source: Internet
Author: User
Tags php script

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.