为什么 gzip 压缩不起作用?

发布于 2024-08-22 22:47:14 字数 560 浏览 3 评论 0 原文

这是一个奇怪的现象。我正在慢慢地在实时服务器上重建网站。站点的某些部分已被重建,因此代码被放置在主目录的子目录中(即:/mysite/newcode)。

我已经使用 ob_start("ob_gzhandler"); 成功对旧站点进行了 gzip 压缩。因此,我为新代码应用了完全相同的代码。然而,由于某种奇怪的原因,它返回时未经过 gzip 压缩。我已经检查了 http://www.whatsmyip.org/http_compression/http://www.gidnetwork.com/tools/gzip-test.php。我不太明白如果 gzip 处理程序作为新旧代码的第一行(在任何输出之前)之一包含在内,为什么它不会对新代码进行 gzip 压缩。

PHP 5.1.6 阿帕奇2.0 森托斯5

This is an odd one. I am slowly rebuilding a website on a live server. Some sections of the site have been rebuilt and therefore the code is placed in a subdirectory of the home dir (ie:/mysite/newcode).

I had successfully gzipped the old site using ob_start("ob_gzhandler"); So, i have applied the exact same code for the new code. However, for some odd reason, its returning as not gzipped. I have checked on http://www.whatsmyip.org/http_compression/ and http://www.gidnetwork.com/tools/gzip-test.php. I can't quite understand why it wouldn't be gzipping the new code if the gzip handler is included as one of the very first lines (before any output) on both old and new code.

PHP 5.1.6
Apache 2.0
Centos 5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半衾梦 2024-08-29 22:47:14

http://docs.php.net/ob_gzhandler 说:

在 ob_gzhandler() 实际发送压缩数据之前,它确定浏览器将接受什么类型的内容编码(“gzip”、“deflate”或根本不接受),并将相应地返回其输出。

Could this be the cause of your problem?

编辑:你可以用类似的东西来测试它

function dbg_ob_gzhandler($buffer, $mode) {
  error_log('dbg_ob_gzhandler invoked');
  $rv = ob_gzhandler($buffer, $mode);
  if ( false===$rv ) {
    error_log('client does not support compressed content');
  }
  return $rv;
}
ob_start('dbg_ob_gzhandler');

http://docs.php.net/ob_gzhandler says:

Before ob_gzhandler() actually sends compressed data, it determines what type of content encoding the browser will accept ("gzip", "deflate" or none at all) and will return its output accordingly.

Could this be the cause of your problem?

edit: You can test this with something like

function dbg_ob_gzhandler($buffer, $mode) {
  error_log('dbg_ob_gzhandler invoked');
  $rv = ob_gzhandler($buffer, $mode);
  if ( false===$rv ) {
    error_log('client does not support compressed content');
  }
  return $rv;
}
ob_start('dbg_ob_gzhandler');
山人契 2024-08-29 22:47:14

发现问题,不确定是否在任何地方记录...

如果您使用 ob_start("ob_gzhandler");你要刷新你的内容,你必须使用ob_flush(),而不是flush()。使用flush会消除压缩。

Found out the problem, not sure if documented anywhere...

If you use ob_start("ob_gzhandler"); and you what to flush your content, you must use ob_flush(), not flush(). Using flush will throw out the compression.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文