PHP控制網(wǎng)頁過期時間的代碼
更新時間:2008年09月28日 10:40:34 作者:
有時我們需要控制主頁之類的網(wǎng)頁過期時間。但我們比如使用的是Chinacache的CDN,那要怎么樣設(shè)計才能讓他緩存我的內(nèi)容.
當(dāng)然,前提要先打開CDN中一個功能reload_into_ims on.這樣用戶發(fā)送過來no-cache也不怕了.因為這樣會給給no-cache轉(zhuǎn)成If-Modified-Since .所以我們寫程序主要是對If-Modified-Since控制就好了.記的,緩存系統(tǒng)架構(gòu)中計中最好是后端來控制,所以最好的方法是程序來管理過期. 呵,我只會php,就用php寫一個,別的程序也是一樣。
見我下面的程序,呵呵,5分鐘過期.
<?php
$headers = apache_request_headers();
$client_time = (isset($headers['If-Modified-Since']) ? strtotime($headers['If-Modified-Since']) : 0);
$now=gmmktime();
$now_list=gmmktime()-60*5;
if ($client_time<$now and $client_time >$now_list){
header('Last-Modified: ‘.gmdate('D, d M Y H:i:s', $client_time).' GMT', true, 304);
exit(0);
}else{
header('Last-Modified: ‘.gmdate('D, d M Y H:i:s', $now).' GMT', true, 200);
}
?>
見我下面的程序,呵呵,5分鐘過期.
復(fù)制代碼 代碼如下:
<?php
$headers = apache_request_headers();
$client_time = (isset($headers['If-Modified-Since']) ? strtotime($headers['If-Modified-Since']) : 0);
$now=gmmktime();
$now_list=gmmktime()-60*5;
if ($client_time<$now and $client_time >$now_list){
header('Last-Modified: ‘.gmdate('D, d M Y H:i:s', $client_time).' GMT', true, 304);
exit(0);
}else{
header('Last-Modified: ‘.gmdate('D, d M Y H:i:s', $now).' GMT', true, 200);
}
?>
相關(guān)文章
php數(shù)組對百萬數(shù)據(jù)進行排除重復(fù)數(shù)據(jù)的實現(xiàn)代碼
在平時的工作中,經(jīng)常接到要對網(wǎng)站的會員進行站內(nèi)信、手機短信、email進行群發(fā)信息的通知,用戶列表一般由別的同事提供,當(dāng)中難免會有重復(fù),為了避免重復(fù)發(fā)送,所以我在進行發(fā)送信息前要對他們提供的用戶列表進行排重,下面我以uid列表來講講我是如何利用php數(shù)組進行排重的。2010-06-06