PHP 8.1.28 Released!

Настройка во время выполнения

Поведение этих функций зависит от установок в php.ini.

Модуль zlib предоставляет возможность сжатия передаваемых страниц (в т.ч. динамических) на лету, если браузер это поддерживает. За сжатие отвечают три параметра в конфигурационном файле php.ini.

Конфигурационные параметры Zlib
Имя По умолчанию Место изменения Список изменений
zlib.output_compression "0" INI_ALL  
zlib.output_compression_level "-1" INI_ALL  
zlib.output_handler "" INI_ALL  
Дополнительная информация и описания режимов INI_* даны в разделе «Места установки параметров конфигурации».

Краткое разъяснение конфигурационных директив.

zlib.output_compression bool/int

Следует ли сжимать страницы. Если значение равно "On" в php.ini (или в настройках Apache), страницы будут сжиматься, если браузер посылает заголовок "Accept-Encoding: gzip" или "deflate". При этом в вывод будут добавлены заголовки "Content-Encoding: gzip" (соответственно "deflate") и "Vary: Accept-Encoding". В режиме исполнения, заголовок должен быть установлен до момента отправки.

Эта опция также принимает целые числа вместо логических "On/Off", с помощью этого вы можете устанавливать размер выходного буфера (по умолчанию равен 4 КБ).

Замечание:

output_handler должен быть пустым, если выбрано значение 'On'! Вместо него следует использовать zlib.output_handler.

zlib.output_compression_level int

Уровень сжатия используется для прозрачного сжатия вывода. Укажите значение между 0 (без сжатия) и 9 (максимальное сжатие). По умолчанию значение -1 позволяет серверу решать, какой уровень использовать.

zlib.output_handler string

Если zlib.output_compression активирован, нельзя указывать дополнительные обработчики вывода. Этот параметр выполняет то же, что и output_handler, но в ином порядке.

add a note

User Contributed Notes 5 notes

up
-3
finlanderid at gmail dot com
9 years ago
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?
up
-5
Anon
4 years ago
Because of possible BREACH attacks when using output compression cross-site scripting should be disallowed. This can be achieved with the same-site cookie attribute:

https://www.sjoerdlangkemper.nl/2016/04/14/preventing-csrf-with-samesite-cookie-attribute/

https://caniuse.com/#feat=same-site-cookie-attribute
up
-7
scott at pawprint dot net
12 years ago
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.
up
-7
pacerier+php dot net at gmail dot com
6 years ago
@finlanderid, Exactly. As output_handler and zlib.output_handler cant be both set (as per ""<output_handler must be empty if this is set 'On'>""), "different order" refers to?
up
-17
galaxy
8 years ago
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 :)
To Top