我认为你的算术有问题;根据您的代码查看以下示例:
$lifetime = 60;
header("Cache-Control: must-revalidate");
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$lastMod = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
} else {
$lastMod = 0;
}
if ($lastMod <= $_SERVER['REQUEST_TIME'] - $lifetime) {
$lastMod = $_SERVER['REQUEST_TIME'];
header("Content-type: text/plain");
header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T', $lastMod), true, 200);
echo "Hello!";
} else {
header("Last-Modified: " . gmdate('D, d M Y H:i:s \G\M\T', $lastMod), true, 304);
}
这将将上次修改的标头设置为现在(使用
$_SERVER['REQUEST_TIME']
这可能比使用
time()
直接),并且在随后的请求中检查if Modified Since是否至少为60秒。如果是,它将刷新(并重新设置上次修改到现在);否则,返回304并且不改变最后修改。