Summary of 9 Major cache technologies in PHP, and summary of PHP 9 Major cache. Summary of the 9 Major cache technologies in PHP, and summary of the PHP 9 Major cache 1. static full-page cache: static html pages generated for all pages, which are directly accessed by users during access, instead of summing up the 9 Major cache technologies in PHP and the PHP 9 Major cache
1. static full-page cache
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 () ******* code to be run ******* $ content = Ob_get_contents (); ***** write the cached content to the 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, you can directly call the information in this file, instead of querying the database. In fact, the cached file contains a php array;
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 once 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;
Connect ($ memcachehost, $ memcacheport) or die ("cocould not connect"); $ memcache-> set ('key', 'cached content '); $ get = $ memcache-> get ($ key); // get 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:
[Apc] 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.
XCache, Turck MM Cache, and PHP Accelerator are well-known.
All-round programmers exchange qq group 290551701 and gather many Internet elites, technical directors, architects, and project managers! Open-source technology research, welcome to the industry, Daniel and beginners interested in IT industry personnel!
Lifecycle 1. static cache of all pages, that is, static html pages are generated on all pages. when users access the static pages directly, they do not...