PHP在cdn中可缓存的动态设计

有时我们需要控制主页之类的网页过期时间,我们的程序主要是对If-Modified-Since控制就好了.记的,缓存系统架构中计中最好是后端来控制,所以最好的方法是程序来管理过期.

<?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);
}

?>

相关日志


技术研究 关键字(Tags): , , ,

如果你觉得这篇文章不错,你可以 给我留个回复订阅它。无论如何,谢谢你的支持!

评论

还没有评论。

发表评论

(必填)

(必填)