Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过PHP设置过期标头_Php_Apache - Fatal编程技术网

通过PHP设置过期标头

通过PHP设置过期标头,php,apache,Php,Apache,我们正在通过php呈现缩小的css/js,其中包含以下过期标题 header('Expires:'.gmdate('D, d M Y H:i:s', 1407595380 + 3600 * 24 * 90).' GMT'); header('Cache-Control: public'); header('Last-Modified: 1407595380'); header('Content-type: text/css'); 响应标题我们被在线提到 Cache-Control publ

我们正在通过php呈现缩小的css/js,其中包含以下过期标题

header('Expires:'.gmdate('D, d M Y H:i:s', 1407595380 + 3600 * 24 * 90).' GMT');
header('Cache-Control: public');
header('Last-Modified: 1407595380');
header('Content-type: text/css');
响应标题我们被在线提到

Cache-Control   public
Connection  Keep-Alive
Content-Encoding    gzip
Content-Length  3224
Content-Type    text/css
Date    Mon, 11 Aug 2014 14:54:55 GMT
Expires Fri, 07 Nov 2014 14:43:00 GMT
Keep-Alive  timeout=5, max=100
Last-Modified   1407595380
Pragma  no-cache
Server  Apache/2.2.22 (Ubuntu)
但每次我刷新页面时,浏览器都会给我200个响应代码,而不是304个。浏览器并没有为php生成的缩小文件使用自己的缓存,并且在后续请求中使用了304代码的RESTCSS js


谢谢,布拉格玛:没有缓存可能会给你线索


尽管它适用于传统HTTP/1.0,但如果您使用Apache,请尝试设置
Pragma:cache

,您可以创建一个.htaccess文件,其内容为:
Header unset Pragma Header set Pragma“cache”
请解释您的答案。所以不仅仅是回答问题,而是学习事情如何以及为什么会发生。
$timeToCache = 3600 * 24 * 90;
header('Expires:'.gmdate('D, d M Y H:i:s', 1407595380 + $timeToCache).' GMT');
header('Cache-Control: public');
header('Cache-Control: max-age='.$timeToCache);
header('Last-Modified: 1407595380');
header('Content-type: text/css');
header('Pragma: cache');