PHP Caching Technology

Source: Internet
Author: User

Full-page static caching is the page all generated HTML static pages, users access to the static page directly, but not to go to the PHP server parsing process. This way, in the CMS system is more common, such as dedecms; a more common implementation is to use output caching: Ob
1. Full page static cache
That is, the page is all generated HTML static page, the user accesses the static page directly, but not to go to the PHP server parsing process. In this way, the CMS system
More common in the system, such as DEDECMS;
A more common way to implement this is with output caching:
Ob_start ()
The code to run *******
$content = Ob_get_contents ();
Write cached content to HTML file * * * *
Ob_end_clean ();
2. Page Partial Cache
In this way, the non-constant parts of a page are statically cached, and the frequently changing blocks are not cached and assembled together to display; you can use similar
Ob_get_contents, you can also use a page fragment caching strategy like ESI to make it a cache of relatively static fragment portions of a dynamic page
(ESI technology, please Baidu, here is unknown).
This method can be used for product pages such as the mall;
3. Data Cache
As the name implies, is a way to cache data, for example, an item in the mall information, when the product ID to request, will be included in the store information, product information
Data, the data can be cached in a PHP file, and the file name contains the product ID to create a unique label; the next time someone wants to view this item, the first
The first is to directly tune the information inside the file, instead of going to the database query, in fact, the cache file cache is a PHP array, and so on;
Ecmall Mall system inside the use of this way;
4. Query Cache
In fact, the data cache is a way of thinking, is based on query statements to cache, the data is cached in a file, the next time you encounter the same query, directly
Then the data from the file, not to check the database, but the cache file name here may need to use a query statement as the base point to establish a unique indicator;
Cache by Time Change
In fact, this is not a true caching method, the above 2, 3, 4 of the cache technology is generally used to determine the time to change; you need to set a valid cache file
Time, in this effective time, the same access will first take the contents of the cache file, but more than the set cache time, you need to re-fetch the data from the database,
and produce the latest cache files;
For example, I will be the home of our mall is set up 2 hours to update;
5. Cache by content Change
This is not an independent caching technology, need to be combined with, that is, when the database content is modified, immediately update the cache file;
For example, a large number of shopping malls, a lot of goods, commodity tables must be relatively large, the pressure of the table is also heavier; we can cache the product display page;
When the merchant changes the information of this product in the background, click Save, we update the cache file at the same time, then, when the buyer accesses this product information, it actually accesses
A static page without having to access the database;
is to think, if the product page does not cache, then each visit to a commodity will go to the database check once, if there are 100,000 people online browsing products, the server pressure is big;
6. In-Memory cache
The first thing you can think of is that memcached;memcached is a high-performance distributed memory cache server. The general purpose of the use is to pass the cache number
Reduce database access times to improve the speed and scalability of dynamic Web applications.
It is to cache the information that needs to be cached in the system memory, need to obtain information, directly into the memory, the more common way is key-->value way;
<?php
$memcachehost = ' 192.168.6.191 ';
$memcacheport = 11211;
$memcachelife = 60;
$memcache = new Memcache;
$memcache->connect ($memcachehost, $memcacheport) or Die ("Could not Connect");
$memcache->set (' key ', ' cached content ');
$get = $memcache->get ($key); Get information
?>
7. Apache Cache Module
After the installation of Apache, the cache is not allowed. If you have a cache or squid server that requires web acceleration, you need to set up a htttpd.conf
The Mod_cache module is activated when you install Apache.
When installing Apache:./configure--enable-cache--enable-disk-cache--enable-mem-cache
8. PHP APC Cache extension
PHP has an APC cache extension, Windows is php_apc.dll, you need to load the module first, and then configure it in php.ini:
[APC]
Extension=php_apc.dll
apc.rfc1867 = On
Upload_max_filesize = 100M
Post_max_size = 100M
Apc.max_file_size = 200M
Upload_max_filesize = 1000M
Post_max_size = 1000M
Max_execution_time = 600; Maximum time value per php page (seconds), default 30 seconds
Max_input_time = 600; The maximum time required for each PHP page to receive data, by default 60
Memory_limit = 128M; Maximum memory consumed per PHP page, default 8M
9. OpCode Cache
We know that PHP's execution process can be used to show:
The execution process of PHP
First, the PHP code is parsed into tokens, and then compiled into opcode code, and finally execute opcode code, return the result; So, for the same PHP file, the first run
can cache its opcode code, the next time you execute this page, will go directly to find the cache opcode code, directly perform the last step, and no longer need the intermediate steps.
More well-known is XCache, Turck MM Cache, PHP accelerator, etc.;

PHP Caching Technology

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.