【发布时间】:2009-06-08 18:17:29
【问题描述】:
我正在设置我认为正确的用于从 PHP 缓存的 HTTP 标头,并且每第二个请求都会收到 500 错误。
谁能指出我正确的方向?
做缓存的代码是:
<?php
header('Content-Type: text/css');
$content = file_get_contents('test.css');
header('Content-Length: '. strlen($content ));
$expires = 3600;
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
// Split the If-Modified-Since (Netscape < v6 gets this wrong)
$modifiedSince = explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
// Turn the client request If-Modified-Since into a timestamp
$modifiedSince = strtotime($modifiedSince[0]);
$current_time = time();
if (($current_time - $modifiedSince) < $expires) {
header("304 Not Modified");
//echo $current_time - $modifiedSince;
exit();
}
}
$current_time = time();
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $current_time)." GMT");
header("Expires: " . gmdate("D, d M Y H:i:s", $current_time+$expires) . " GMT");
header("Cache-Control: max-age=$expires");
echo $content;
谢谢
编辑 1: 我没有高兴地清除了我的缓存,有人报告说它对他们有用。这是否意味着服务器配置问题?如果重要,它在托管服务器上。
编辑 2:在 IE 中似乎不会发生,但在 Firefox 中会发生
【问题讨论】:
-
对我来说没问题。尝试清除浏览器缓存。您可能已经缓存了 500 或其他内容。
-
没有快乐。这是否意味着您需要配置服务器?