[英]Cache-Control Header Modified By PHP Session?
I'm outputting an image to the browser using a Zend_Controller_Response
object. 我正在使用Zend_Controller_Response
对象将图像输出到浏览器。 It is my intention to apply caching to the image, however something is causing the Cache-Control header to be overwritten. 我打算将缓存应用于图像,但是有些东西会导致Cache-Control标头被覆盖。
My code is as follows: 我的代码如下:
$this->getResponse()
->setHeader('Last-Modified', $modifiedTime, true)
->setHeader('ETag', md5($modifiedTime), true)
->setHeader('Expires', $expires, true)
->setHeader('Pragma', '', true)
->setHeader('Cache-Control', 'max-age=3600')
->setHeader('Content-Type', $mimeType, true)
->setHeader('Content-Length', $size, true)
->setBody($data);
The output (as viewed in Firebug) is: 输出(在Firebug中查看)是:
Response Headers 响应标题
- Date 日期
- Wed, 25 Mar 2009 10:34:40 GMT 2009年3月25日星期三,格林威治标准时间10:34:40
- Server 服务器
- Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c Apache / 2.2.3(Ubuntu)mod_ssl / 2.2.3 OpenSSL / 0.9.8c
- Expires 过期
- Thu, 26 Mar 2009 10:34:41 GMT 星期四,2009年3月26日10:34:41 GMT
- Cache-Control 缓存控制
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=3600 no-store,no-cache,must-revalidate,post-check = 0,pre-check = 0,max-age = 3600
- Last-Modified 上一次更改
- 1234872514 1234872514
- Etag ETAG
- d3ef646c640b689b0101f3e03e08a524 d3ef646c640b689b0101f3e03e08a524
- Content-Length 内容长度
- 1452 1452
- X-UA-Compatible X-UA兼容
- IE=EmulateIE7 IE = EmulateIE7
- X-Robots-Tag X-Robots-Tag中
- noindex NOINDEX
- Keep-Alive 活着
- timeout=15, max=100 超时= 15,最大= 100
- Connection 连接
- Keep-Alive 活着
- Content-Type 内容类型
- image/jpeg 图像/ JPEG
Request Headers 请求标题
- Host 主办
- khall.####.###.######.com khall。####。###。######。com
- User-Agent 用户代理
- Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.7) Gecko/2009030422 Ubuntu/8.04 (hardy) Firefox/3.0 .7 Mozilla / 5.0(X11; U; Linux i686; en-US; rv:1.9.0.7)Gecko / 2009030422 Ubuntu / 8.04(hardy)Firefox / 3.0 .7
- Accept 接受
- text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 text / html的,应用/ XHTML + xml的,应用/ XML; Q = 0.9,* / *; Q = 0.8
- Accept-Language 接受语言
- en-gb,en;q=0.5 烯GB,EN; Q = 0.5
- Accept-Encoding 接受编码
- gzip,deflate gzip的,放气
- Accept-Charset 接收字符
- ISO-8859-1,utf-8;q=0.7,*;q=0.7 ISO-8859-1,utf-8; Q = 0.7,*; Q = 0.7
- Keep-Alive 活着
- 300 300
- Connection 连接
- keep-alive 活着
- Referer 引荐
- http://khall.####.###.######.com/ HTTP://khall.####.###.######.com/
- Cookie 曲奇饼
- PHPSESSID=abf5056e1289d3010448107632a1c1bd PHPSESSID = abf5056e1289d3010448107632a1c1bd
As you can see, the cache control is modified to include: 如您所见,缓存控件被修改为包括:
no-store, no-cache, must-revalidate, post-check=0, pre-check=0 no-store,no-cache,must-revalidate,post-check = 0,pre-check = 0
My suspicion is towards the session cookie being sent in the request. 我怀疑是在请求中发送会话cookie。 Does anybody know a way to send the header that I require, yet still keep the session in the request? 有没有人知道发送我需要的标题的方法,但仍然在请求中保持会话? My application is run through a bootstrap, and sessions are handled using Zend_Session. 我的应用程序通过引导程序运行,并使用Zend_Session处理会话。
Any help would be appreciated. 任何帮助,将不胜感激。
You're right by assuming that this behaviour is connected to the session mechanism in PHP. 您是正确的,假设此行为已连接到PHP中的会话机制。 There is a configuration setting session.cache_limiter
that controls the caching HTTP headers that will be sent with the response. 有一个配置设置session.cache_limiter
,它控制将随响应一起发送的缓存HTTP标头。 The default setting here is nocache
which sends 这里的默认设置是发送的nocache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
You overwrite all of these headers within your controller besides the Cache-Control
-header (you only append your max-age=3600
setting here). 除了Cache-Control
-header之外,您还会覆盖控制器中的所有这些标头(您只需在此处附加max-age=3600
设置)。
Possible solutions are: 可能的解决方案是
session.cache_limiter
) to eg none
- but this could introduce problems to other PHP applications 将PHP配置( session.cache_limiter
)更改为例如none
- 但这可能会给其他PHP应用程序带来问题 session.cache_limiter
on each request using session_cache_limiter()
使用session_cache_limiter()
每个请求设置session.cache_limiter
Cache-Control
-header in your controller with the designated string 用指定的字符串覆盖控制器中的完整Cache-Control
-header The possible values for session.cache_limiter
and session_cache_limiter()
are: session.cache_limiter
和session_cache_limiter()
的可能值为:
none : no header will be sent none :不会发送标头
nocache : nocache :
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
private : 私人的 :
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private, max-age=10800, pre-check=10800
private_no_expire : private_no_expire :
Cache-Control: private, max-age=10800, pre-check=10800
public : 公众 :
Expires: pageload + 3 hours
Cache-Control: public, max-age=10800
From the Zend_Controller documentation, section 10.9. 从Zend_Controller文档,第10.9节。 The Response Object 响应对象
setHeader($name, $value, $replace = false) is used to set an individual header. setHeader($ name,$ value,$ replace = false)用于设置单个标头。 By default, it does not replace existing headers of the same name in the object; 默认情况下,它不会替换对象中同名的现有标头; however, setting $replace to true will force it to do so. 但是,将$ replace设置为true将强制它这样做。
The problem you are having is your max-age=3600 is being appended to the cache-control header, as opposed to replacing it. 你遇到的问题是你的max-age = 3600被附加到缓存控制头,而不是替换它。 Try setting the $replace parameter to true . 尝试将$ replace参数设置为true 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.