Php static cache improves website access speed implementation code

Source: Internet
Author: User
Php static cache improves website access speed implementation code
I wrote a code using php static cache to speed up website access. if you need it, refer to it.

1. the following code requirements: 1. the system supports php 2. file_get_contents file_put_contents [can be replaced with functions of the same purpose] 3. it is best to support gzcompress

II. usage 1. download the huncun. php file 2. create the folder huancun (or other) 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 include ("/huancun. php "); 6. clear Cache

III. disadvantages 1. when using this system, you cannot update the content in real time. you must clear the cache before updating the content or set the cache Time. 2. the first access speed is slow because there is no cache. the second is to call the cache file, and then it will be faster. 3. cache files occupy disk space. we recommend that you use a large server or space. or regularly delete cached files.

Example,

     = $ 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.