Example
Add gzip compression to a page:
html
<?php
ob_start("ob_gzhandler");
echo "Hello World!";
?>
Definition and Usage
This function is intended to be passed as a callback to ob_start(). It compresses the contents of the output buffer using a compression algorithm that is supported by the browser and returns the compressed content. It also sends an HTTP header indicating which compression algorithm was used.
Syntax
When used as a callback for ob_start():
text
ob_start("ob_gzhandler");
When used on its own:
text
ob_gzhandler(buffer, phase);
Parameter Values
| Parameter | Description |
|---|---|
| buffer | The contents of the output buffer |
| phase | A bitmask which may have any number of the following flags: PHP_OUTPUT_HANDLER_START - If the output buffer was just created PHP_OUTPUT_HANDLER_FLUSH - If the output buffer is currently being flushed PHP_OUTPUT_HANDLER_FINAL - If the output buffer will be deleted right after this operation |
Technical Details
| Return Value: | Returns a string containing the compressed contents |
|---|---|
| PHP Version: | 4.0.4+ |