【发布时间】:2011-03-01 17:06:55
【问题描述】:
我正在使用 PHP 5.3 和 Apache 2.0 来提供一个脚本,该脚本在输出中添加了许多标头:
header('HTTP/1.1 200 OK');
header("Content-Type: application/json");
header("Last-Modified: $lastmode"); // $lastmod = Tue, 01 Mar 2011 14:56:22 +0000
header("Etag: $etag"); // Etag = 5da02274fcad09a55f4d74467f66a864
现在,除了Last-Modified 和Etag 之外,所有标题都通过了。在我的 httpd.conf 中,我有以下内容:
Header unset Cache-Control
Header unset Pragma
但在我的回复中,我得到:
HTTP/1.1 200 OK
Date: Tue, 01 Mar 2011 16:49:10 GMT
Server: Apache/2.2.14 (EL) mod_ssl/2.2.14 OpenSSL/0.9.8e-fips-rhel5
Keep-Alive: timeout=15, max=8000
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json
Expires: 0
Cache-Control: no-cache
我的 Last-Modified 和 Etag 标头不见了,我们用 Cache-Control 和 Expires 代替了它们。
我还应该提到,我已禁用 mod_expires 无济于事。此时我正在拔头发,因为无论我做什么,标题都不存在。什么可能导致它们被删除?
谢谢, J
更新:似乎 Apache 在 PHP 关闭后添加了额外的标头,我认为它也删除了我在上面设置的标头。在PHP中注册一个关闭函数并调用apache_response_headers显示:
Pragma=
Expires=
Etag=5da02274fcad09a55f4d74467f66a864
Last-Modified=Tue, 01 Mar 2011 14:56:22 +0000
Keep-Alive=timeout=15, max=8000
Connection=Keep-Alive
Transfer-Encoding=chunked
Content-Type=application/json
【问题讨论】:
-
$lastmode和$etag是什么值? -
抱歉,我已更新问题以显示值。