php Simple cache site-wide function introduction
- function cache_page($refresh=20){
- ob_start();//Open buffer
- $hash=sha1($_SERVER[PHP_SELF].|G|.serialize($_GET).|P|.serialize($_POST)) ; //Cache file name
- $file=dirname(__FILE__)./cache/.$hash;//Cache file path
- if(!file_exists($file)) {// The cache file does not exist
- register_shutdown_function(cache_page_go,$file);
- }else{// The cache file exists
- if( (time()-filemtime($file) )>$refresh ){//Cache timeout
- register_shutdown_function(cache_page_go,$file);//Call function
- }
- else{//Use cache file normally
- $f=file_get_contents($file);// Get cached file content
- echo $f. Cached;//Output cached content
- $output=ob_get_contents (); //Get the buffer content
- ob_get_clean(); //Clear the buffer
- echo $output; //Output
- exit();
- }
- }
- }
-
- function cache_page_go($file){
- $output=ob_get_contents(); //Get buffer contents
- ob_get_clean(); //Clear buffer
- file_put_contents($file,$output,LOCK_EX);//Write cache file
- echo $output. Newly created;//Output cache content
- exit();
- }
- ?>
-
http://www.bkjia.com/PHPjc/486191.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486191.htmlTechArticlephp Simple cache full-site function introduction?php function cache_page($refresh=20){ ob_start();/ /Open buffer $hash=sha1($_SERVER[PHP_SELF].|G|.serialize($_GET).|P|.serialize($_POST));...