@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?
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.
Nom | Défaut | Modifiable | Historique |
---|---|---|---|
zlib.output_compression | "0" | PHP_INI_ALL | Disponible depuis PHP 4.0.5. |
zlib.output_compression_level | "-1" | PHP_INI_ALL | Disponible depuis PHP 4.3.0. |
zlib.output_handler | "" | PHP_INI_ALL | Disponible depuis PHP 4.3.0. |
Voici un éclaircissement sur l'utilisation des directives de configuration.
zlib.output_compression
booléen/entier
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
entier
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
chaîne de caractères
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.
@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?
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?
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 :)
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.
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);
?>