Configurações em Execução

O comportamento dessas funções podem ser modificado pelas configurações do php.ini.

A extensão zlib oferece a opção de comprimir transparentemente suas páginas em tempo real, se o navegador requisitante suportar isto. Então existem três opções no arquivo de configuração php.ini.

Opções de Configuração da Zlib
Nome Padrão Modificável Changelog
zlib.output_compression "0" PHP_INI_ALL  
zlib.output_compression_level "-1" PHP_INI_ALL  
zlib.output_handler "" PHP_INI_ALL  
Para mais detalhes e definições dos modos PHP_INI_*, veja Onde uma configuração deve ser definida.

Uma rápida explicação das diretivas de configuração.

zlib.output_compression bool/int

Indica se as páginas deverm ser comprimidas de modo transparente. Se esta opção for mudada para "On" no php.ini ou na configuração do Apache, as páginas serão comprimidas se o navegador enviar um cabeçalho "Accept-Encoding: gzip" ou "deflate". "Content-Encoding: gzip" (respectivamente "deflate") e cabeçalhos "Vary: Accept-Encoding" serão adicionados para a saida. Em tempo de execução, isso só pode ser definido antes de enviar qualquer saída.

Esta opção também aceita valores inteiros em vez de valores booleanos "On"/"Off", usando isto você pode configurar o tamanho do buffer de saída (o padrão é 4KB).

Nota:

output_handler deve estar vazio se a diretriz estiver configurada em 'On'! Em vez disso, utilize zlib.output_handler.

zlib.output_compression_level int

Nível de compressão utilizado. Especifique um valor entre 0 (sem compressão) ou 9 (compressão máxima). O valor padrão -1 permite ao servidor escolher que nível utilizar.

zlib.output_handler string

Você não pode especificar tratamentos adicionais de saída se zlib.output_compression for ativado. Esta configuração faz o mesmo que a output_handler mas em uma ordem diferente.

add a note add a note

User Contributed Notes 6 notes

up
0
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
-4
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
-3
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
-2
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
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 :)
up
-21
Nathan
12 years ago
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);
?>
To Top