CakeFest 2024: The Official CakePHP Conference

Configuración en tiempo de ejecución

El comportamiento de estas funciones se ve afectado por la configuración de php.ini.

La extensión zlib ofrece la opción de comprimir de manera trasparente las páginas sobre la marcha, si el navegador que hace la solicitud lo soporta. Por lo tanto hay tres opciones en el archivo de configuración php.ini.

Opciones de Configuración de Zlib
Nombre Por defecto Cambiable Historial de cambios
zlib.output_compression "0" INI_ALL  
zlib.output_compression_level "-1" INI_ALL  
zlib.output_handler "" INI_ALL  
Para más detalles y definiciones de los modos de INI_*, vea Dónde se puede realizar un ajuste de configuración.

He aquí una breve explicación de las directivas de configuración.

zlib.output_compression bool/int

Para comprimir páginas transparentemente. Si esta opción está configurada en "On" en php.ini o en la configuración de Apache, las páginas serán comprimidas si el navegador envía un encabezado "Accept-Encoding: gzip" o "deflate". Los encabezados "Content-Encoding: gzip" (respectivamente "deflate") y "Vary: Accept-Encoding" serán agregados a la salida. En tiempo de ejecución, esto se puede configurar sólo antes de enviar cualquier salida.

Esta opción también acepta valores enteros (integer) en lugar de boolean en "On"/"Off", usando esto se puede configurar el tamaño del buffer de salida (por defecto es 4KB).

Nota:

output_handler debe estar vacío si ésta se configura en 'On' ! De otra manera se debe usar zlib.output_handler.

zlib.output_compression_level int

Nivel de compresión usado para la salida de la compresión transparente. Especifica un valor entre 0 (no comprimido) y 9 (máxima compresión). El valor por defecto es -1, que deja que el servidor decida cual nivel utilizar.

zlib.output_handler string

No se pueden especificar manejadores adicionales de salida si zlib.output_compression está activada aquí. Esta configuración hace lo mismo que output_handler pero en un orden diferente.

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