PHP dynamic website static cache speed up website access

Source: Internet
Author: User
Tags php dynamic website
Some php websites are purely dynamic or mostly dynamic due to preliminary design and other reasons, and database operations are frequent, resulting in slow website access! I want to achieve static without generating static functions. because I have written a simple static program, it is very simple. at first glance, I understand that it is suitable for the basic...

Some php websites are designed in the early stage and for other reasons.
Websites are purely dynamic or mostly dynamic, and database operations are frequent.
This slows down website access! The static function is not generated.
Because I wrote a simple static program, which is easy to understand at a glance.
Suitable for basically all systems

Requirements
1. the system supports php
2. support for file_get_contents file_put_contents [can also be replaced by functions with the same function]
3. it is best to support gzcompress

Usage
1. download the huncun. php file shared below
2. create the folder huancun (or others) in the root directory of the website)
3. copy huncun. php to the huancun directory.
4. create a folder cache directory under the huancun Directory
5. load the file on a public website file header or a static webpage header.
Include ("/huancun. php ");
6. clear cache reference http://www.oschina.net/code/snippet_202258_7018

Disadvantages
1. the system cannot update the content in real time. the content must be cleared before it can be updated or updated only when the specified cache time is reached.
2. the first access was slow because there was no cache. The second access was to call the cache file, which was faster.
3. cache files occupy disk space. we recommend that you use a large server or space or regularly delete cached files.

 

= $ Cachetime) {$ return = file_get_contents ($ cachename); $ data = function_exists (gzcompress )? @ Gzuncompress ($ return): $ return; return unserialize ($ data);} else {$ return = file_get_contents ($ cacheurl); HC_writecache ($ cachename, $ return ); return $ return ;}} function HC_writecache ($ name, $ array) {function_exists (gzcompress )? $ Return = gzcompress (serialize ($ array): $ return = serialize ($ array); @ file_put_contents ($ name, $ return);}?>

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.