PHP 網(wǎng)頁過期時(shí)間的控制代碼
更新時(shí)間:2009年06月29日 21:51:24 作者:
有時(shí)我們需要控制主頁之類的網(wǎng)頁過期時(shí)間。但我們比如使用的是Chinacache的CDN,那要怎么樣設(shè)計(jì)才能讓他緩存我的內(nèi)容.
當(dāng)然,前提要先打開CDN中一個(gè)功能reload_into_ims on.這樣用戶發(fā)送過來no-cache也不怕了.因?yàn)檫@樣會(huì)給給no-cache轉(zhuǎn)成If-Modified-Since .所以我們寫程序主要是對(duì)If-Modified-Since控制就好了.記的,緩存系統(tǒng)架構(gòu)中計(jì)中最好是后端來控制,所以最好的方法是程序來管理過期. 呵,我只會(huì)php,就用php寫一個(gè),別的程序也是一樣。
見我下面的程序,呵呵,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常見過waf webshell以及最簡(jiǎn)單的檢測(cè)方法
這篇文章主要給大家介紹了關(guān)于PHP常見過waf webshell以及最簡(jiǎn)單的檢測(cè)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用PHP具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05php.ini save_handler 修改不生效的解決辦法
這篇文章主要介紹了php.ini save_handler 修改不生效的解決辦法,需要的朋友可以參考下2014-07-07