mackjoner / php-ext-brotli
Brotli Extension for PHP, Documentation for Brotli can be found at https://github.com/google/brotli/.
Requires
- php: ^5.3.3 || ^7.0
This package is not auto-updated.
Last update: 2025-06-14 19:11:39 UTC
README
This extension allows Brotli compression.
Documentation for Brotli can be found at » https://github.com/google/brotli/.
Build
% 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-libbrotli
Distribution binary packages
Fedora / CentOS / RHEL
RPM packages of this extension are available in » Remi's RPM repository and are named php-brotli.
Configuration
brotli.ini:
extension=brotli.so
Function
- brotli_compress — Compress a string
- brotli_uncompress — Uncompress a compressed string
brotli_compress — Compress a string
Description
string brotli_compress ( string $data [, int $quality = 11, int $mode = -1 ] )
This function compress the given string using the ZLIB data format.
Parameters
-
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).
Return Values
The compressed string or FALSE if an error occurred.
brotli_uncompress — Uncompress a compressed string
Description
string brotli_uncompress ( string $data [, int $length = 0 ] )
This function uncompress a compressed string.
Parameters
-
data
The data compressed by brotli_compress().
-
length
The maximum length of data to decode.
Return Values
The original uncompressed data or FALSE on error.
Examples
$compressed = brotli_compress('Compresstest');
$uncompressed = brotli_uncompress($compressed);
echo $uncompressed;