File cache, PHP file cache
Not much to say, look at the code
head.php
Phpdefine ('Cache_expire',1800); Set expiration time define ('Cache_path', $_server['Document_root'].'/cache/'); Set the cache directory define ('Refresh_expire',Ten); Is_dir (Cache_path) or mkdir (Cache_path,0777);
This method is to get the user's refresh number, if the user refreshes two times in a row, then display the latest content function Refreshtimes () {$CURRENTURL='/ http'. $_server["Http_host"].$_server['Request_uri']; if(Isset ($_cookie['Refreshtimes']) {$cookArray=explode ("\ t", $_cookie['Refreshtimes']); if(Isset ($cookArray [1]) and $_server['Request_time'] - (int) $cookArray [1] < Refresh_expire and Isset ($cookArray [0]) and $cookArray [0] ==$currentUrl) {Setcookie ('Refreshtimes', $currentUrl."\ t". $_server['Request_time']."\ t". (string)((int) $cookArray [2]+1),0,'/'); return(int) $cookArray [2]; }Else{Setcookie ('Refreshtimes', $currentUrl."\ t". $_server['Request_time']."\t1",0,'/'); return 0; } }Else{Setcookie ('Refreshtimes', $currentUrl."\ t". $_server['Request_time']."\t1",0,'/'); return 0; }} $key= MD5 ($_server['Request_uri']); $path=Cache_path. $key;if(Is_file ($path) and Filemtime ($path)+cache_expire > $_server['Request_time'] and refreshtimes ()==0) {ReadFile ($path); Exit ();} Ob_start ();?>
foot.php
php$html = ob_get_contents (); Ob_clean () file_put_contents ($path, $html); Echo $html; >
test.php
' head.php ' "Hello world~";? > "-//w3c//dtd XHTML 1.0 transitional//en""http://www.w3.org/TR/xhtml1/ DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml"> "
content-type " content="text/html; charset=gb2312" /><?php Echo $title?>
" is generous and generous " ;? >
'foot.php';? >
Others see a very full PHP file cache
See http://www.cnblogs.com/coolid/archive/2012/09/14/2684373.html Links
http://www.bkjia.com/PHPjc/1109846.html www.bkjia.com true http://www.bkjia.com/PHPjc/1109846.html techarticle file cache, php file cache not much to say, see Code head.php? Phpdefine (' Cache_expire ', 1800);//Set Expiration Time define (' Cache_path ', $_server[' DOCU Ment_root ']. ' /...