Some PHP sites are due to upfront design and other reasons
The Web site is dynamic or mostly dynamic, and the database operates very frequently.
Cause Web site access is very slow! Want to implement static, without generating static functionality.
Because I wrote a streamlined process for generating static. It's simple, it's easy to read.
Suitable for basically all systems
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
How to use
1. Download the following shared huncun.php file
2. Create a folder Huancun (or other) in the root directory of the Web site
3. Copy huncun.php to Huancun directory
4. Build folder cache directory under the Huancun directory
5. Load this file on the header of a Web site public file or on a static web page
Include ("/huancun/huancun.php");
6. Empty Cache Reference http://www.oschina.net/code/snippet_202258_7018
Disadvantages
1. The use of the system can not update the content in real time must empty the cache before updating or to the set cache time will be updated
2. The first visit is slower because there is no caching. The second time is to call the cache file, which is fast.
3. cache files for disk space, it is recommended that the server or a larger use of space. Or periodically delete cached files
<?php/*www.diyphp.net *www.php100.com */if ($_get[' Phphuancun ']!= ' true ') {define ("Hc_path", DirName (__file__). " /cache/"); Define ("Hc_time", 1); Echo Hc_getcache (); exit; function Hc_getcache ($iscache = ') {$url = ' http://'. $_server[' server_name '].$_server[' Request_uri ']; $cacheurl = Strpos ($url, "?")? $url. " &phphuancun=true ": $url."? Phphuancun=true "; $cachename =hc_path.md5 ($url). " C "; $cachetime = $iscache Time () +1:time ()-(Hc_time * 60*60); if (file_exists ($cachename) && filemtime ($cachename) >= $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); }?>