PHP Squid中可緩存的動態(tài)網頁設計
更新時間:2008年09月17日 13:28:34 作者:
有時我們需要控制主頁之類的網頁過期時間.但我們比如使用的是Chinacache的CDN,那要怎么樣設計才能讓他緩存我的內容.
當然,前提要先打開CDN中一個功能reload_into_ims on.這樣用戶發(fā)送過來no-cache也不怕了.因為這樣會給給no-cache轉成If-Modified-Since .所以我們寫程序主要是對If-Modified-Since控制就好了.記的,緩存系統(tǒng)架構中計中最好是后端來控制,所以最好的方法是程序來管理過期.呵,我只會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分鐘過期.
<?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);
}
?>
相關文章
Windows下PHP開發(fā)環(huán)境搭建教程(Apache+PHP+MySQL)
這篇文章主要為大家詳細介紹了Windows下PHP開發(fā)環(huán)境搭建教程:Apache+PHP+MySQL,具有一定的實用性和參考價值,感興趣的小伙伴們可以參考一下2016-06-06