如何检查 PHP 是否启用了 gzip 压缩?
(function_exists('ob_gzhandler') && ini_get('zlib.output_compression'))
足够了吗?
我想检查主机是否在其中一个页面中提供压缩页面:)
Is (function_exists('ob_gzhandler') && ini_get('zlib.output_compression'))
enough ?
I want to check if the host is serving compressed pages within one of the pages :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于 PHP,他们会做得很好。
但是,如果您指的是将页面压缩回客户端,您还需要检查它是否在 apache 中启用(假设您使用 apache,您将需要 mod_gzip.c 或 mod_deflate.c 模块)。
例如:
# httpd -l
(apache 2)我过去也看到过需要实现 .htaccess 覆盖:
For PHP, they'll do fine.
However, if your referring to compression of pages back to clients, you'll also need to check it's enabled in apache (assuming your using apache you'll need the mod_gzip.c OR mod_deflate.c modules).
For instance:
# httpd -l
(apache 2)Ive also seen mention of needing to implement .htaccess overrides in the past:
您
可以找到模块是否已加载
或
此网站 https://www.giftofspeed.com/gzip -test/
可以检查某个页面的压缩是否开启。
通过这些,您将了解压缩是否足以满足您的需要。
With
You could find if the module is loaded
or
This website https://www.giftofspeed.com/gzip-test/
You can check if the compression on a certain page is enabled.
With those you'll see if the compression is enough for you.
你可以从 php 以编程方式执行此操作:
这当然不是超级可靠,因为可能还有其他压缩模块......
you can do this programmatically from php:
This is of course not super reliable, because there might be other compression modules...
我有一个类,它根据对 css 或 js 文件的 get 请求检查是否启用了 gzip 压缩,然后尝试输出相应的压缩 css 或 js 文件(如果已启用)或常规文件(如果未启用)。
如果您只查看如何检查 gszip 是否已启用,那么这些类的 isPhpGzCompressionInProcess 方法可以帮助您,但在大多数情况下,您需要基于它处理一些输出,我很确定该类的其余部分可以帮助某人也。
I have a class that checks based on a get request to css or js file if gzip compression is enabled and then tries to output corresponding compressed css or js file if it's enabled or a regular file if it's not.
If you are looking only at how to check if gszip is enabled then isPhpGzCompressionInProcess method of these class can help you but in most cases, you need to process some output base on it and I am pretty sure that the rest of the class can help someone too.