檔案快取,php檔案快取_PHP教程

來源:互聯網
上載者:User

檔案快取,php檔案快取


不多說,看代碼

Head.php

phpdefine('CACHE_EXPIRE',1800);  //設定到期時間define('CACHE_PATH',$_SERVER['DOCUMENT_ROOT'].'/cache/'); //設定緩衝目錄define('REFRESH_EXPIRE',10);  is_dir(CACHE_PATH) or mkdir(CACHE_PATH,0777);
//該方法是獲得使用者的重新整理次數,如果使用者連續兩次重新整理,那麼就顯示最新內容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

phpinclude 'head.php';$title = "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?>phpecho "是大方大方";?>phpinclude 'foot.php';?>

//其他看到的很全的php檔案快取

看http://www.cnblogs.com/coolid/archive/2012/09/14/2684373.html 連結

http://www.bkjia.com/PHPjc/1109846.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1109846.htmlTechArticle檔案快取,php檔案快取 不多說,看代碼 Head.php ? phpdefine( ' CACHE_EXPIRE ' , 1800 ); //設定到期時間define( ' CACHE_PATH ' ,$_SERVER[ ' DOCUMENT_ROOT ' ]. ' /...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.