从PHP缓存头文件

从PHP缓存头文件,php,apache,http,browser-cache,http-caching,Php,Apache,Http,Browser Cache,Http Caching,在PHP中,默认情况下不发送与缓存相关的头 HTTP/1.1 200 OK Date: Fri, 19 Nov 2010 11:02:16 GMT Server: Apache/2.2.15 (Win32) PHP/5.2.9-2 X-Powered-By: PHP/5.2.9-2 Vary: Accept-Encoding Content-Encoding: gzip Content-Length: 26 Keep-Alive: timeout=5, max=100 Connection: K

在PHP中,默认情况下不发送与缓存相关的头

HTTP/1.1 200 OK
Date: Fri, 19 Nov 2010 11:02:16 GMT
Server: Apache/2.2.15 (Win32) PHP/5.2.9-2
X-Powered-By: PHP/5.2.9-2
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 26
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

现在,由于默认情况下它没有提到缓存,因此在某些情况下它会导致例如example.com/index.php被缓存吗?

是的,如果服务器端没有设置规则,浏览器通常会默认缓存某些文件(通常是图像和css)(请参阅)

您可以设置缓存控制标头来控制此操作,或使用以下方法完全禁用它:

header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 
header("Pragma: no-cache");
请参见中的示例#2并阅读下面的注释

在某些情况下,它会导致example.com/index.php被缓存吗

不应该这样,但是有很多实现(特别是在移动设备/移动代理上)在这方面表现不正确

还有很多关于缓存的错误信息——“Pragma:no cache”是从服务器发送的

要防止缓存,请执行以下操作:

header("Cache-Control: no-store, no-cache, must-revalidate"); 
当所有其他操作都失败时-

是。一般而言,除非有以下情况:

除非受到cache control()指令的特别约束,否则缓存系统可能会始终将成功响应(请参阅)存储为缓存条目,如果响应是新的,则可能会在未经验证的情况下返回,并且可能会在验证成功后返回