304 Not Modified issue(304未修改问题)
问题描述
对不起,可能是错误的标题.我正在编写一些代码来处理 If-Modified-Since 和 If-None-Match 请求作为缓存的一部分.除了 PHP 在标题之后返回一些内容(一个空行)之外,一切都很完美.页面内容应该是空的.我使用的代码是:
Sorry for the probably wrong title. I am writing some code to handle If-Modified-Since and If-None-Match requests as part of caching. Everything works perfect except for that PHP returns some content (an empty line) after the headers. The page content should be empty instead. The code that I am using is:
<?php
$lastmod = filemtime($f);
$etag = '"'.dechex($lastmod).'"';
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $last_mod || $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
header('HTTP/1.1 304 Not Modified');
header('Content-Length: 0');
exit();
}
?>
推荐答案
终于解决了这个bug.Gzip 是罪魁祸首.由于我也在压缩对 If-Modified-Since 和 If-None-Match 请求的响应,因此 gzip 在响应中添加了一些字节(一种 gzip 标头).现在我停止了对 If-Modified-Since 和 If-None-Match 请求的 gzip 响应,它就像一个魅力.
Finally solved this bug. Gzip was the culprit. Since I was gzipping the responses to If-Modified-Since and If-None-Match requests too, gzip was adding a few bytes (kind of a gzip header) to the response. Now I have stopped gzipping responses to If-Modified-Since and If-None-Match requests, and it works like a charm.
这篇关于304未修改问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:304未修改问题
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
