简体   繁体   English

无法覆盖PHP中的Cache-Control

[英]Cannot overwrite Cache-Control in PHP

I've moved a older site to a new server, and the client has found a very odd behaviour. 我已经将旧站点移到了新服务器上,客户端发现了一个非常奇怪的行为。

Very close to the end, I have this code: 非常接近结尾,我有以下代码:

if (!$this->cache) {
    header('Expires: '.gmdate('d M Y H:i:s', 946684800).' GMT');
    header('Cache-Control: no-cache');
    header('Pragma: no-cache');
}

Now the odd thing is the Cache-Control line doesnt work. 现在奇怪的是Cache-Control行不起作用。 After packet sniffing I see this: 数据包嗅探后,我看到以下内容:

Expires: 01 Jan 2000 00:00:00 GMT
Cache-Control: max-age=300, public
Pragma: no-cache

The order of the headers is exactly how I set them, but the Cache-Control is completely different. 标头的顺序与我设置标头的顺序完全相同,但是Cache-Control完全不同。 I've grepped my code for any mention of cache-control and there is only that mention, and another one designed to force caching in a different file but it is a different line to what I'm seeing so it cant be the culprit. 我已经在代码中提到了缓存控制,只提到了这一点,还有另一个旨在强制在另一个文件中进行缓存,但这与我看到的内容有所不同,因此不能成为罪魁祸首。

Does anyone know why Cache-Control is changing? 有谁知道为什么高速缓存控件正在更改?

我认为您正在运行Squid,应检查以下配置:

header_replace Cache-Control max-age=300, public

If you are using sessions, it's possible that PHP is overwriting them. 如果使用会话,则PHP可能会覆盖它们。 Take a look at session_cache_limiter() in the manual. 看一下手册中的session_cache_limiter()

Alternatively, you can try setting those headers after you call session_start() . 另外,您可以在调用session_start()之后尝试设置这些标头。

(Edit: I missed the bit about "Very close to the end," so maybe this isn't your problem.) (编辑:我错过了有关“非常接近尾声”的内容,所以也许这不是您的问题。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM