PHP static cache implementation code to improve website access speed

Source: Internet
Author: User
Tags delete cache
Write a static cache using PHP to improve the speed of the site's code, the need for friends, you can refer to the next.

One, the following code requirements: 1. The system supports PHP 2. Support File_get_contents file_put_contents [can also be replaced with functions of the same function] 3. Best support Gzcompress

Ii. use Method 1. Download the huncun.php file that you shared below 2. Huancun (or other) 3. Copy huncun.php to Huancun directory under 4. In the Huancun directory, create the folder cache directory 5. Load this file ("/huancun/huancun.php") in the header of the Web site common file header or both to generate static Web pages; 6. Emptying the cache

Third, disadvantage 1. Using this system cannot update content in real time the cache must be emptied before it can be updated or the cache time is set to update 2. The first access is slower because there is no cache. The second time is to call the cache file, then it's fast 3. cache files for disk space, It is recommended to use a server or a larger space. Or periodically delete cache 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.