How to use PHP Cache? PHP Cache can speed up website opening and reduce server load. There are many implementation methods for PHP Cache. Today, we mainly choose several typical cases to briefly describe them, in future articles, we will describe each caching mechanism in detail. First, let's talk about cache.
1. what is cache? Cache is a "space-for-time" policy and a common method to improve performance. The Cache mechanism is usually used to relieve the burden on databases and disks under high traffic volumes. An Effective Application Cache mechanism can greatly reduce the number of database and disk operations. What are the cache methods of PHP?
2. cache triggered by time Check whether the file exists and the timestamp is earlier than the set expiration time. if the modified timestamp of the file is greater than the current timestamp minus the expiration timestamp, use the cache; otherwise, update the cache.
3. cache triggered by time Check whether the file exists and the timestamp is earlier than the set expiration time. if the modified timestamp of the file is greater than the current timestamp minus the expiration timestamp, use the cache; otherwise, update the cache.
4. file cache This method uses the data queried by the database as the cache content. if the queried data is an array, we can serialize the array and save it to another php file, when you want to read the content, you can deserialize it to get an array of query results. This avoids repeated queries to the database. (Note: the speed of reading files is faster than that of querying the database, but it is necessary to avoid too many files, so as to perform too many I/O operations on the hard disk, thus affecting the speed. Therefore, cache files must also be integrated .)
5. memory cache The internal cache should also be a type of data cache. it is to cache the data queried by the database in the memory and share the memory block. This method can be achieved through the extension software. Currently, the mainstream is memcache.
6. static pages Static page generation is to generate static html, so that the program directly requests this html file upon next access, avoiding PHP re-compilation and database query. Smarty template cache.
7. PHP module cache PHP has an APC cache extension, which is php_apc.dll in windows. you need to load this module first.
8. MYSQL cache MYSQL has its own cache mechanism. you need to adjust the configuration file my. ini.
9. PHP buffer: Software such as eAccelerator, xcache, and Zend Optimizer can optimize and dynamically cache content, which improves the cache performance of php scripts and completely eliminates the server overhead when compiling PHP scripts.
10. server cache Data Caching is implemented through the web server cache mechanism, such as APACHE mod_mem_cache, mod_disk_cache, and mod_cache.
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