php檔案快取技術實現代碼_PHP教程

來源:互聯網
上載者:User
下面是一個php快取檔案實作類別,根據我的經驗,快取檔案是根據使用者佈建的時間與檔案產生的日間以及目前時間進行比較,然後再判斷是否需要重建快取檔案。*/

下面是一個php教程快取檔案實作類別,根據我的經驗,快取檔案是根據使用者佈建的時間與檔案產生的日間以及目前時間進行比較,然後再判斷是否需要重建快取檔案。*/
class pagecache {

/**
* @var string $file 快取檔案地址
* @access public
*/
public $file;

/**
* @var int $cachetime 緩衝時間
* @access public
*/
public $cachetime = 3600;

/**
* 建構函式
* @param string $file 快取檔案地址
* @param int $cachetime 緩衝時間
*/
function __construct($file, $cachetime = 3600) {
$this->file = $file;
$this->cachetime = $cachetime;
}

/**
* 取緩衝內容
* @param bool 是否直接輸出,true直接轉到快取頁面,false返回緩衝內容
* @return mixed
*/
public function get($output = true) {
if (is_file($this->file) && (time()-filemtime($this->file))<=$this->cachetime && !$_get['nocache']) {
if ($output) {
header('location:' . $this->file);
exit;
} else {
return file_get_contents($this->file);
}
} else {
return false;
}
}

/**
* 設定緩衝內容
* @param $content 內容html字串
*/
public function set($content) {
$fp = fopen($this->file, 'w');
fwrite($fp, $content);
fclose($fp);
}
}


http://www.bkjia.com/PHPjc/444822.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444822.htmlTechArticle下面是一個php快取檔案實作類別,根據我的經驗,快取檔案是根據使用者佈建的時間與檔案產生的日間以及目前時間進行比較,然後再判斷是否...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.