Brotli Extension for PHP
Switch branches/tags
Clone or download
Latest commit 45971e4 May 8, 2018

Brotli Extension for PHP

Build Status

This extension allows Brotli compression.

Documentation for Brotli can be found at »


% git clone --recursive --depth=1
% 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.




  • brotli_compress — Compress a string
  • brotli_uncompress — Uncompress a compressed string

brotli_compress — Compress a string


string brotli_compress ( string $data [, int $quality = 11, int $mode = -1 ] )

This function compress the given string using the ZLIB data format.


  • 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) or BROTLI_FONT (for WOFF 2.0).

Return Values

The compressed string or FALSE if an error occurred.

brotli_uncompress — Uncompress a compressed string


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.

Return Values

The original uncompressed data or FALSE on error.


$compressed = brotli_compress('Compresstest');

$uncompressed = brotli_uncompress($compressed);

echo $uncompressed;