PHP Common Caching Method:

Source: Internet
Author: User

PHP Common Caching Method:
The first type of data that needs to be cached is processed to form files that PHP can execute directly. When you need to cache the data, introduce it by using the Include method and use it.
Second, the required data is serialized through the Serialize function and saved directly to the file. When you need to use cached data, read the contents of the file and copy it to the desired variable by deserializing it, and then use the.

Test results:
By testing, we found that the second way of serialize caching data is more efficient. (data omitted, finally provided the article address download, you can Test yourself)

Reason Analysis:
Include way to read the cache, PHP needs to perform several procedures
1. Read the file
2. Resolve the files contained in
3. Execution, assigning values to variables

While serialize reads the cache in a serialized way:
1. Reading data
2. Deserialization of data content
3. Assigning values to variables

In contrast, it is possible that parsing an array in a PHP file takes more time than unserialize deserializing the array. If you are interested you can view the performance efficiency study of PHP filesystem related functions and include require: http://www.ccvita.com/163.html

Test file Code:
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

Summary and Analysis:
First, the way include caching
Advantages: Increase the confidentiality of data, and security, cache content will not be found outside.
Disadvantage: The speed is relatively slow.
Use: Save data that is not known outside the system, such as Web system settings, and even MySQL information.
Second, serialize the way the cache is serialized
Advantages: Faster.
Disadvantage: Cache system file path a little exposure, cache content will be leaked.
Use: Cache the latest articles, related articles, etc. do not worry about external data, you can use this method.

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.