PHP Common caching way to get started tutorial

Source: Internet
Author: User

PHP Common caching way to get started tutorial
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 data

, introduced by the include method, and used.
Second, the required data is serialized through the Serialize function and saved directly to the file. When you need to use the cache

Data, read the contents of the file by deserializing it and copy it to the desired variable, and then use the.

Test results:
By testing, we found that the second way of serialize caching data is more efficient. (Data omitted,

Finally provide 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, this may be due to the time required to parse the array in the PHP file over the unserialize counter

The time the array was serialized. If you are interested you can view the PHP filesystem related functions and include

Research on the performance efficiency of 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.

Note:
After installing the PHP memory cache such as EA and APC, the first way to read cache through include is higher than

Two ways of serialize serialization caching. So in the moophp framework, we use the first

Two ways to cache: Sensitive information is cached in the first way

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.