当网络服务器自动压缩输出时,如何设置正确的 Content-Length 标头?

发布于 2024-08-22 00:20:50 字数 381 浏览 2 评论 0原文

按照我之前的问题,我认为我已经缩小了范围问题归结为瓶颈:

当网络服务器(apache)自动压缩输出时,如何从 PHP 中为可下载文件的 Content-Length 标头设置正确的值?

我正在寻找最强大/通用的解决方案。我对输出压缩不太了解,但我认为 apache 有几种可以利用的压缩算法(gzip 等?)。因此,在 PHP 中,我如何自动发现网络服务器使用的压缩方式,以及如何使用它为文件的文件大小设置正确的 Content-Length 标头值(压缩后) )?

Following my previous question, in which I think I've narrowed my problem down to the bottleneck:

How do I set the correct value for the Content-Length header for a downloadable file, from within PHP, when the webserver (apache) automatically compresses the ouput afterwards?

I'm looking for the most robust/generic solution. I'm not well informed about output compression, but I presume apache has several compression algorithms it can utilize (gzip, etc?). So, from within PHP, how would I automatically discover what compression the webserver uses, and how can I use this to set the correct Content-Length header value for the filesize of the file (after it's been compressed)?

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

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

发布评论

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

评论(3

尘曦 2024-08-29 00:20:51

您不需要指定Content-Length,Apache 会为您做到这一点。

You don’t need to specify Content-Length, Apache does that for you.

第几種人 2024-08-29 00:20:51

好的,这里的情况是您发出文件下载。我敢打赌该文件已经被压缩以节省一些带宽。

无论如何,如果您的服务器启用了任何压缩,那就不好了,因为服务器无法实现更好的压缩,所以会浪费时间,因此为了加快速度,您应该禁用任何文件下载的输出压缩。

尝试这些:

apacheconf
禁用 mod_deflate

php.ini
输出缓冲 = 关闭
输出处理程序=
zlib.output_compression = 关闭

Okay, so the situation here is you issue a file download. I bet that file is already compressed to save you some bandwidth.

Anyway, if your server has any compression active, that's not good, as it spends time for nothing as the server can't achieve a better compression, so for speeding this up, you should disable output compress for any file download.

try from these:

apache conf
Disable mod_deflate

php.ini
output_buffering = Off
output_handler =
zlib.output_compression = Off

简单气质女生网名 2024-08-29 00:20:51

也许cletus在这个问题 有帮助。

另外,您确定要使用 gzip 提供下载服务吗?压缩对于 HTML、CSS 和 JS 内容很有意义,但对于大量文件下载,我会关闭它。

Maybe cletus's answer in this question helps.

Also, are you sure you want to serve your downloads using gzip? Zipping makes much sense for HTML, CSS and JS contents, but with huge file downloads, I would turn it off.

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