CakeFest 2024: The Official CakePHP Conference

Laufzeit-Konfiguration

Das Verhalten dieser Funktionen wird durch Einstellungen in der php.ini beeinflusst.

Die zlib-Erweiterung gibt Ihnen die Möglichkeit, Ihre Seiten on-the-fly transparent zu komprimieren, wenn der Browser dies unterstützt. Dafür gibt es drei Optionen in der Konfigurationsdatei php.ini.

Zlib-Konfigurationsoptionen
Name Standard Veränderbar Changelog
zlib.output_compression "0" INI_ALL  
zlib.output_compression_level "-1" INI_ALL  
zlib.output_handler "" INI_ALL  
Weitere Details und die Definitionen der INI_*-Konstanten sind unter Wo Konfigurationseinstellungen gesetzt werden können zu finden.

Hier eine kurze Erklärung der Konfigurationsoptionen:

zlib.output_compression bool/int

Wenn diese Option in der php.ini oder der Apachekonfiguration auf "On" gesetzt ist, werden die Seiten komprimiert, wenn der Browser einen "Accept-Encoding: gzip"- oder einen "deflate"-Header sendet. Zu den normalerweise vom Server gesendeten Headern werden nun "Content-Encoding: gzip" (respektive "deflate") und "Vary: Accept-Encoding" hinzugefügt. Zur Laufzeit kann die Option nur gesetzt werden, bevor irgendeine Ausgabe gesendet wurde.

Diese Option akzeptiert auch Integerwerte anstelle des boolschen On/Off. Wenn Sie diese verwenden, können Sie die Ausgabepuffergröße festlegen (der Standardwert ist 4KB).

Hinweis:

output_handler muss leer sein, wenn diese Option den Wert "On" hat! Verwenden Sie statt dessen zlib.output_handler.

zlib.output_compression_level int

Der Kompressionsgrad für die transparente Ausgabekomprimierung. Geben Sie einen Wert zwischen 0 (keine Kompression) und 9 (stärkste Kompressionsrate) an. Der Vorgabewert -1 lässt den Server darüber entscheiden, welcher Kompressionsgrad zu verwenden ist.

zlib.output_handler string

Sie können keine zusätzlichen Outputhandler angeben, wenn Sie zlib.output_compression aktiviert haben. Diese Einstellung tut das Gleiche wie output_handler, allerdings in einer anderen Reihenfolge.

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