[英]Using php how can I check if GZIP is turned on?
I am not asking for an online tool.我不是要在线工具。 I'm also not asking how to turn on or turn off gzip.
我也不是在问如何打开或关闭 gzip。
What I want to know, is how, within my php, that I can check to see if gzip will encode the current buffer or not.我想知道的是,如何在我的 php 中检查 gzip 是否会对当前缓冲区进行编码。
If you mean that you want to know whether or not mod_deflate in Apache has been activated, there's no API in PHP to determine that.如果您的意思是您想知道 Apache 中的 mod_deflate 是否已激活,则 PHP 中没有 API 可以确定。 You could, obviously, use a shell command and parse the output, but it's probably not the preferred way.
显然,您可以使用 shell 命令并解析 output,但这可能不是首选方式。 The question is though: why should PHP care if the output is gzipped?
问题是:为什么 PHP 应该关心 output 是否被压缩?
I'm not 100% sure what you mean by gzip will encode the current buffer
but i assume you mean "compress the output before sending it"我不是 100% 确定
gzip will encode the current buffer
但我假设您的意思是“在发送之前压缩 output”
if(ini_get("zlib.output_compression")) {
echo "On";
} else {
echo "off";
}
Should you be talking about ob_*
functions and output streams there is ob_get_status
but afaik you can't check if that was started with ob_gzhandler()
or not.如果您在谈论
ob_*
函数和 output 流,则存在ob_get_status
但 afaik 您无法检查是否以ob_gzhandler()
开头。 Your application would have to track that.您的应用程序必须跟踪它。 But zlib compression is preferred anyways
但无论如何,zlib 压缩是首选
probably like so:大概是这样的:
ini_get('zlib_output_compression');
(for the manual see here: http://php.net/manual/en/function.ini-get.php ) (手册见这里: http://php.net/manual/en/function.ini-get.php )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.