我最近开始在我的网站上使用gzip,它在除Opera之外的所有浏览器上运行得很好,因为它提供了一个错误,指出由于数据损坏而无法解压内容。从我可以从测试和搜索结果中收集的信息,可能会同时使用gzip和分块传输编码。在请求像css文件这样的小文件时没有错误的事实也指出了这一点。使用分块传输编码和gzip
这是一个已知问题还是有没有其他的东西,我没有想过?
有人还提到它可能与发送Content-Length标题有关。
这里是我的代码的最相关部分的简化版本:
$contents = ob_get_contents();
ob_end_clean();
header('Content-Encoding: '.$encoding);
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
$size = strlen($contents);
$contents = gzcompress($contents, 9);
$contents = substr($contents, 0, $size);
print($contents);
exit();
你的第一个输出是什么意思,你为什么在这种情况下使用'substr'? – Gumbo 2010-04-30 06:57:42