PHP 8.3.4 Released!

Configuration à l'exécution

Le comportement de ces fonctions est affecté par la configuration dans le fichier php.ini.

L'extension zlib offre l'option de compresser de manière transparente les pages PHP à la volée, si le navigateur du visiteur le supporte. Voici donc les trois options à utiliser dans le fichier de configuration php.ini.

Options de configuration Zlib
Nom Défaut Modifiable Historique
zlib.output_compression "0" INI_ALL  
zlib.output_compression_level "-1" INI_ALL  
zlib.output_handler "" INI_ALL  
Pour plus de détails sur les modes INI_*, reportez-vous à Où une directive de configuration peut être modifiée.

Voici un éclaircissement sur l'utilisation des directives de configuration.

zlib.output_compression bool/int

Active ou pas la compression transparente des pages. Si cette option est mise à "On" dans php.ini ou dans la configuration Apache, les pages sont compressées si le navigateur envoie un en-tête "Accept-Encoding: gzip" ou "deflate". Les en-têtes "Content-Encoding: gzip" (respectivement "deflate") et "Vary: Accept-Encoding" sont ajoutés dans la page envoyée au navigateur. En fonctionnement, il peut être défini uniquement avant tout affichage.

Cette option accepte aussi des valeurs entières au lieu des booléens, "On"/"Off", ce qui vous permet de configurer la taille du tampon de sortie (par défaut, il vaut 4ko).

Note:

output_handler doit être laissée à vide si cette option est activée. Sinon, vous devez utiliser zlib.output_handler.

zlib.output_compression_level int

Niveau de compression utilisé pour la compression de sortie. La valeur doit être comprise entre 0 (aucune compression) et 9 (compression élevée). La valeur par défaut est -1, ce qui laissera le serveur décider du niveau de compression à utiliser.

zlib.output_handler string

Vous ne pouvez pas spécifier de gestionnaire de sortie supplémentaire si zlib.output_compression est activée. Cette configuration est la même que output_handler mais dans un ordre différent.

add a note

User Contributed Notes 5 notes

up
-3
finlanderid at gmail dot com
8 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