文字

运行时配置

这些函数的行为受 php.ini 中的设置影响。

The zlib extension offers the option to transparently compress your pages on-the-fly, if the requesting browser supports this. Therefore there are three options in the configuration file php.ini.

Zlib Configuration Options
名字 默认 可修改范围 更新日志
zlib.output_compression "0" PHP_INI_ALL Available since PHP 4.0.5.
zlib.output_compression_level "-1" PHP_INI_ALL Available since PHP 4.3.0.
zlib.output_handler "" PHP_INI_ALL Available since PHP 4.3.0.
有关 PHP_INI_* 样式的更多详情与定义,见 配置可被设定范围。

这是配置指令的简短说明。

zlib.output_compression boolean / integer

Whether to transparently compress pages. If this option is set to "On" in php.ini or the Apache configuration, pages are compressed if the browser sends an "Accept-Encoding: gzip" or "deflate" header. "Content-Encoding: gzip" (respectively "deflate") and "Vary: Accept-Encoding" headers are added to the output. In runtime, it can be set only before sending any output.

This option also accepts integer values instead of boolean "On"/"Off", using this you can set the output buffer size (default is 4KB).

Note:

output_handler must be empty if this is set 'On' ! Instead you must use zlib.output_handler.

zlib.output_compression_level integer

Compression level used for transparent output compression. Specify a value between 0 (no compression) to 9 (most compression). The default value, -1, lets the server decide which level to use.

zlib.output_handler string

You cannot specify additional output handlers if zlib.output_compression is activated here. This setting does the same as output_handler but in a different order.

用户评论:

[#1] galaxy [2015-06-18 10:49:21]

finlanderid at gmail dot com,

you are mixing two separate things and consider them to be the same thing, hence the confusion.

There are two output_handlers:

1. http://php.net/manual/en/outcontrol.configuration.php#ini.output-handler

2. http://php.net/manual/en/zlib.configuration.php#ini.zlib.output-handler

Now, if you re-read your quotes again with this information it won't be confusing anymore :)

[#2] finlanderid at gmail dot com [2015-03-21 06:42:01]

Does anyone find these two statements contradictory? Am I not understanding something, or are these statements actually contradicting each other? 

Statement ONE from output_handler:
"output_handler must be empty if this [zlib.output_compression] is set 'On' ! Instead you must use zlib.output_handler."

Statement TWO from zlib.output_handler:
"You cannot specify additional output handlers if zlib.output_compression is activated ..."

Statement ONE says you have to use zlib.output_handler, if zlib.output_compression is turned ON. Statement TWO says that, if zlib.output_compression is turned ON, you cannot use zlib.output_handler. 

what the heck?

[#3] scott at pawprint dot net [2012-02-29 18:19:38]

In the hopes this will help others - a hard to spot gotcha when implementing zlib.output_compression. if you use flush() anywhere in your script (even right at the end) the compression won't work - you need to let that happen automatically or it ends up being sent uncompressed.

[#4] Nathan [2011-11-08 20:53:30]

Apparently, there is a bug in certain versions of PHP with setting zlib.output_compression to "On" via ini_set: 

<?php
ini_set
("zlib.output_compression""On");
?>


In some cases, it does not send the Content-type header and browsers won't know to decompress the contents before displaying. Instead, you can set it to the buffer size, which sends the correct header:

<?php
ini_set
("zlib.output_compression"4096);
?>

上一篇: 下一篇: