This extension allows Brotli compression.
Documentation for Brotli can be found at » https://github.com/google/brotli/.
% git clone --recursive --depth=1 https://github.com/kjdev/php-ext-brotli.git % cd php-ext-brotli % phpize % ./configure % make $ make install To use the system library (using pkg-config)
% ./configure --with-libbrotliRPM packages of this extension are available in » Remi's RPM repository and are named php-brotli.
brotli.ini:
extension=brotli.so | Name | Default | Changeable |
|---|---|---|
| brotli.output_compression | 0 | PHP_INI_ALL |
| brotli.output_compression_level | -1 | PHP_INI_ALL |
-
brotli.output_compression boolean
Whether to transparently compress pages. If this option is set to "On" in php.ini or the Apache configuration, pages are compressed if the browser sends an "Accept-Encoding: br" header. "Content-Encoding: br" and "Vary: Accept-Encoding" headers are added to the output. In runtime, it can be set only before sending any output.
-
brotli.output_compression_level integer
Compression level used for transparent output compression. Specify a value between 0 to 11. The default value of -1 uses internally defined values (11).
Available since PHP 5.4.0.
| Name | Description |
|---|---|
| BROTLI_COMPRESS_LEVEL_MIN | Minimal compress level value |
| BROTLI_COMPRESS_LEVEL_MAX | Maximal compress level value |
| BROTLI_COMPRESS_LEVEL_DEFAULT | Default compress level value |
- brotli_compress — Compress a string
- brotli_uncompress — Uncompress a compressed string
string brotli_compress ( string $data [, int $quality = 11, int $mode = -1 ] )
This function compress a string.
-
data
The data to compress.
-
quality
The higher the quality, the slower the compression. (Defaults to 11)
-
mode
The compression mode can be
BROTLI_GENERIC(default),BROTLI_TEXT(for UTF-8 format text input) orBROTLI_FONT(for WOFF 2.0).
The compressed string or FALSE if an error occurred.
string brotli_uncompress ( string $data [, int $length = 0 ] )
This function uncompress a compressed string.
-
data
The data compressed by brotli_compress().
-
length
The maximum length of data to decode.
The original uncompressed data or FALSE on error.
Namespace Brotli; function compress( $data [, $quality = 11, $mode = -1 ] ) function uncompress( $data [, $length = 0 ] ) brotli_compress, brotli_uncompress function alias.
Brotli compression and uncompression are available using the compress.brotli:// stream prefix.
$compressed = brotli_compress('Compresstest'); $uncompressed = brotli_uncompress($compressed); echo $uncompressed;ini_set('brotli.output_compression', 'On'); // OR // ob_start('ob_brotli_handler'); echo ...;"Accept-Encoding: br" must be specified.
$data = \Brotli\compress('test'); \Brotli\uncompress($data);file_put_contents("compress.brotli:///patch/to/data.br", $data); readfile("brotli.brotli:///patch/to/data.br");