File Cache, PHP File Cache
Read the code.
Head. php
<? Phpdefine ('cache _ EXPIRE ', 1800); // set the expiration time define ('cache _ path', $ _ SERVER ['document _ root']. '/cache/'); // set the cache directory define ('refresh _ EXPIRE ', 10); is_dir (CACHE_PATH) or mkdir (CACHE_PATH, 0777 );
// This method obtains the number of user refreshes. If the user refreshes twice in a row, the latest function refreshTimes () {$ currentUrl = 'HTTP: // 'is displayed ://'. $ _ 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 ', $ curren TUrl. "\ 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
<? Phpinclude 'head. php'; $ title = "Hello world ~ ";?> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
// Others can see the full PHP File Cache
View http://www.cnblogs.com/coolid/archive/2012/09/14/2684373.html links