PHP 9 cache technology summary_php-php Tutorial

Source: Internet
Author: User
Tags apc php server
That is, generate all html static pages. the static pages accessed by users are not parsed by the php server. This method is common in CMS systems, such as dedecms. the following section describes the php9 cache technology summary. 1. static cache on the entire page is required.

That is, generate all html static pages. the static pages accessed by users are not parsed by the php server. This method is common in CMS systems, such as dedecms;

A common implementation method is to use the output cache:

Ob_start ()

* ***** The code to run *******

$ Content = Ob_get_contents ();

***** Write cached content to an html file *****

Ob_end_clean ();

2. partial page cache

In this way, the parts that are not frequently changed in a page are static cached, but the frequently changed blocks are not cached and finally assembled and displayed together. it can be implemented in a way similar to ob_get_contents, you can also use a page fragment caching policy like ESI to cache relatively static parts of a dynamic page (ESI technology, please refer to baidu for details here ).

This method can be used, for example, on the product page in the mall;

3. data cache

As the name suggests, it is a way to cache data. for example, when a product information in the mall is requested by the product id, data including store information and product information will be obtained, in this case, you can cache the data to a php file. the file name contains the item id to create a unique identifier. The next time someone wants to view this item, first, directly call the information in this file, instead of querying the database; in fact, the cache file caches a php array and the like;

This method is used in the Ecmall mall system;

4. query cache

In fact, this is a way of thinking with data cache, that is, to cache data based on query statements; to cache the queried data in a file, the next time you encounter the same query, you can call the data directly from the file without querying the database. However, the cache file name here may need to create a unique identifier based on the query statement;

Cache by time change

In fact, this is not a real cache method. the cache Technologies 2, 3, and 4 above generally use the time change judgment, that is, you need to set a valid time for cached files, during this validity period, the content of the cached file is obtained for the same access. However, if the specified cache time is exceeded, the data needs to be retrieved from the database again, and produce the latest cached files. for example, I set the homepage of our mall to be updated every two hours;

5. cache based on content changes

This is not an independent caching technology, and should be used in combination; that is, when the database content is modified, the cache file is immediately updated;

For example, in a mall with a large volume of traffic and a large number of commodities, the commodity table must be relatively large, and the pressure on this table is also heavy; we can cache the page of the commodity display page;

When a merchant modifies the product information in the background, click save and we will update the cache file at the same time. when the buyer accesses the product information, it actually accesses a static page, instead of accessing the database;

Imagine that if the product page is not cached, the database will be checked every time a product is accessed. if 0.1 million people browse the product online, the server will be under heavy pressure;

6. memory cache

Memcached is a high-performance distributed memory cache server. The general purpose is to reduce the number of database accesses by caching database query results, so as to speed up dynamic Web applications and improve scalability.

It caches the information to be cached to the system memory. when you need to obtain the information, you can directly retrieve it from the memory. the more common method is the key-> value method;

<? Php $ memcachehost = '2017. 168.6.191 '; $ memcacheport = 11211; $ memcachelife = 60; $ memcache = new Memcache; $ memcache-> connect ($ memcachehost, $ memcacheport) or die ("cocould not connect"); $ memcache-> set ('key', 'cached content'); $ get = $ memcache-> get ($ key ); // Obtain information?>

7. apache Cache module

After apache is installed, it cannot be cached. If the external cache or squid server requires web acceleration, you need to set it in htttpd. conf, provided that the mod_cache module is activated during apache installation.

When installing apache:./configure-enable-cache-enable-disk-cache-enable-mem-cache

8. php APC cache extension

Php has an APC cache extension, which is php_apc.dll in windows. you need to load this module first and then configure it in php. ini:

Extension = php_apc.dll apc. rfc1867 = on upload_max_filesize = 100 M post_max_size = 100 M apc. max_file_size = 200 M upload_max_filesize = 1000 M post_max_size = 1000 M max_execution_time = 600; maximum time (in seconds) for running each PHP page. the default value is 30 seconds. max_input_time = 600; maximum time required for receiving data on each PHP page. the default value is 60 memory_limit = 128 M. The maximum memory consumed by each PHP page is 8 M by default.

9. Opcode cache

We know that the php execution process can be used to demonstrate:

First, the php code is parsed to Tokens, and then compiled to the Opcode code. Finally, the Opcode code is executed to return the result. Therefore, the Opcode code can be cached during the first running of the same php file, the next time you execute this page, you will find the cached opcode and execute the last step without any intermediate steps.

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.