PHP Squid中可缓存的动态网页设计
更新时间:2008年09月17日 13:28:34 作者:
有时我们需要控制主页之类的网页过期时间.但我们比如使用的是Chinacache的CDN,那要怎么样设计才能让他缓存我的内容.
当然,前提要先打开CDN中一个功能reload_into_ims on.这样用户发送过来no-cache也不怕了.因为这样会给给no-cache转成If-Modified-Since .所以我们写程序主要是对If-Modified-Since控制就好了.记的,缓存系统架构中计中最好是后端来控制,所以最好的方法是程序来管理过期.呵,我只会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);
}
?>
相关文章
解析zend studio中直接导入svn中的项目的方法步骤
本篇文章是对zend studio中直接导入svn中的项目的方法步骤进行了详细的分析介绍,需要的朋友参考下2013-06-06
详解WordPress开发中get_header()获取头部函数的用法
这篇文章主要介绍了详解WordPress开发中get_header()获取头部的用法,get_header()函数在WordPress主题的制作中一定会用到,需要的朋友可以参考下2016-01-01


最新评论