How do I use PHP caching?

Source: Internet
Author: User
Tags smarty template
PHP cache can speed up the opening of the Web site, reduce server load, etc., for the implementation of the PHP cache a lot, today mainly choose a few more typical examples as a simple explanation, the future article will be a detailed description of each cache mechanism, first of all we have to say what is the cache.
1. What is cache
Caching is a "space-for-time" strategy, which is a common approach to high performance. The caching mechanism is usually used to alleviate the burden of database and disk under large traffic, and the effective application caching mechanism can greatly reduce the number of operations on database and disk, and what is the way of PHP caching?
2. Time-Triggered cache
Check that the file exists and that the timestamp is less than the expiration time of the setting, and if the timestamp of the file modification is greater than the current timestamp minus the expiration timestamp, then cache is used, otherwise the cache is updated.
3. Time-Triggered cache
Check that the file exists and that the timestamp is less than the expiration time of the setting, and if the timestamp of the file modification is greater than the current timestamp minus the expiration timestamp, then cache is used, otherwise the cache is updated.
4. File Cache
This way is the database query out of the data as the content of the cache, if the query is an array of data, we can serialize this array and then save in a php file, when you want to read the content can be deserialized to get a query result array. Avoid repeated queries to the database. (Note: The speed of reading files is faster than querying the database, but to avoid too many files, so that the hard disk IO operation too much, thereby affecting the speed, so the cache file should be in close planning. )
5. Memory Cache
The intrinsic cache should also be one of the data caches, in which the data queried by the database is cached in memory and shared in the memory block. This approach can be achieved by extending the software, and now the main mainstream is memcache
6. Static page
Page generation static is to generate static HTML, so that the next time the program access to the HTML file directly, to avoid the re-compilation of PHP and database query. Smarty Template Cache.
7. PHP Module Cache
PHP has an APC cache extension, and Windows is Php_apc.dll, which requires the module to be loaded first.
8. mysql Cache
MySQL comes with its own caching mechanism and needs to adjust the configuration file My.ini.
9. PHP Buffers:
Eaccelerator, XCache, Zend Optimizer and other software can optimize and dynamic content cache, improve the cache performance of PHP script, so that PHP script in the state of compilation, the cost of the server almost completely eliminated.
10. Server Cache
Through the caching mechanism of Web server, the data cache is implemented, for example: Apache Mod_mem_cache, Mod_disk_cache, Mod_cache, etc.
  • 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.