• Stars
    star
    171
  • Rank 222,266 (Top 5 %)
  • Language
    C
  • License
    MIT License
  • Created about 9 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Brotli Extension for PHP

Brotli Extension for PHP

Linux Windows

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

php.ini:

extension=brotli.so

Output handler option

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.

Constant

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

Function

  • brotli_compress β€” Compress a string
  • brotli_uncompress β€” Uncompress a compressed string
  • brotli_compress_init β€” Initialize an incremental compress context (PHP 7)
  • brotli_compress_add β€” Incrementally compress data (PHP 7)
  • brotli_uncompress_init β€” Initialize an incremental uncompress context (PHP 7)
  • brotli_uncompress_add β€” Incrementally uncompress data (PHP 7)

brotli_compress β€” Compress a string

Description

string brotli_compress ( string $data [, int $quality = BROTLI_COMPRESS_LEVEL_DEFAULT, int $mode = BROTLI_GENERIC ] )

This function compress a string.

Parameters

  • data

    The data to compress.

  • quality

    The higher the quality, the slower the compression. (Defaults to BROTLI\_COMPRESS\_LEVEL\_DEFAULT)

  • 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

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.


brotli_compress_init β€” Initialize an incremental compress context

Description

resource brotli_compress_init ( [ int $quality = BROTLI_COMPRESS_LEVEL_DEFAULT, int $mode = BROTLI_GENERIC ] )

Initialize an incremental compress context. (PHP 7)

Parameters

  • quality

    The higher the quality, the slower the compression. (Defaults to BROTLI\_COMPRESS\_LEVEL\_DEFAULT)

  • 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

Returns a brotli context resource (brotli.state) on success, or FALSE on failure.


brotli_compress_add β€” Incrementally compress data

Description

string brotli_compress_add ( resource $context, string $data [, $mode = BROTLI_PROCESS ] )

Incrementally compress data. (PHP 7)

Parameters

  • context

    A context created with brotli_compress_init().

  • data

    A chunk of data to compress.

  • mode

    One of BROTLI_PROCESS (default), BROTLI_FINISH.

    BROTLI_FINISH to terminate with the last chunk of data.

Return Values

Returns a chunk of compressed data, or FALSE on failure.


brotli_uncompress_init β€” Initialize an incremental uncompress context

Description

resource brotli_uncompress_init ( void )

Initialize an incremental uncompress context. (PHP 7)

Return Values

Returns a brotli context resource (brotli.state) on success, or FALSE on failure.


brotli_uncompress_add β€” Incrementally uncompress data

Description

string brotli_uncompress_add ( resource $context, string $data [, $mode = BROTLI_PROCESS ] )

Incrementally uncompress data. (PHP 7)

Parameters

  • context

    A context created with brotli_uncompress_init().

  • data

    A chunk of compressed data.

  • mode

    One of BROTLI_PROCESS (default), BROTLI_FINISH.

    BROTLI_FINISH to terminate with the last chunk of data.

Return Values

Returns a chunk of uncompressed data, or FALSE on failure.

Namespace

Namespace Brotli;

function compress( $data [, $quality = \\BROTLI\_COMPRESS\_LEVEL\_DEFAULT, $mode = \\BROTLI\_GENERIC ] )
function uncompress( $data [, $length = 0 ] )
function compress\_init( [ $quality = \\BROTLI\_COMPRESS\_LEVEL\_DEFAULT, $mode = \\BROTLI\_GENERIC ] )
function compress\_add( resource $context, string $data [, $mode = \\BROTLI\_PROCESS] )
function uncompress\_init()
function uncompress\_add( resource $context, string $data [, $mode = \\BROTLI\_PROCESS] )

alias functions..

Streams

Brotli compression and uncompression are available using the compress.brotli:// stream prefix.

Examples

$compressed = brotli_compress('Compresstest');

$uncompressed = brotli_uncompress($compressed);

echo $uncompressed;

Output handler

ini_set('brotli.output_compression', 'On');
// OR
// ob_start('ob_brotli_handler');

echo ...;

"Accept-Encoding: br" must be specified.

Namespace

$data = \Brotli\compress('test');

\Brotli\uncompress($data);

Streams

file_put_contents("compress.brotli:///patch/to/data.br", $data);
readfile("compress.brotli:///patch/to/data.br");

Incrementally

// compression
$resource = brotli_compress_init();
$compressed = '';
$compressed .= brotli_compress_add($resource, 'Hello, ', BROTLI_PROCESS);
$compressed .= brotli_compress_add($resource, 'World!', BROTLI_PROCESS);
$compressed .= brotli_compress_add($resource, '', BROTLI_FINISH);

echo brotli_uncompress($compressed), PHP_EOL; // Hello, World!

// uncompression
$resource = brotli_uncompress_init();
$uncompressed = '';
$uncompressed .= brotli_uncompress_add($resource, substr($compressed, 0, 5), BROTLI_PROCESS);
$uncompressed .= brotli_uncompress_add($resource, substr($compressed, 5), BROTLI_PROCESS);
$uncompressed .= brotli_uncompress_add($resource, '', BROTLI_FINISH);

echo $uncompressed, PHP_EOL; // Hello, World!

More Repositories

1

php-ext-zstd

Zstd Extension for PHP
C
204
star
2

php-ext-lz4

LZ4 Extension for PHP
PHP
149
star
3

php-ext-snappy

Snappy Extension for PHP
PHP
127
star
4

apache-mod-brotli

mod_brotli is Brotli compression module for Apache HTTPD Server.
C
61
star
5

php-ext-handlersocketi

PHP HandlerSocket plugin for MySQL Improved Extension
C
44
star
6

php-ext-jq

This extension allows jq
PHP
41
star
7

php-redis-graph

RedisGraph PHP Client
PHP
40
star
8

php-ext-unqlite

UnQLite Extension for PHP
C
34
star
9

hoextdown

Hoextdown is an extension to Hoedown
C
23
star
10

nginx-auth-jwt

Nginx module for the authenticate using JWT
C
20
star
11

nginx-keyval

Nginx module for the key-value store
Perl
19
star
12

php-ext-hoedown

PHP Extension for Hoedown
PHP
16
star
13

php-ext-zopfli

This extension allows Zopfli compression.
PHP
16
star
14

apache-mod-sass

mod_sass is Sass handler module for Apache HTTPD Server.
C
10
star
15

php-ext-vedis

PHP Extension for Vedis
C
6
star
16

php-ext-msgpacki

PHP MessagePack Improved Extension
PHP
6
star
17

php-ext-sophia

PHP Extension for Sophia
C
6
star
18

apache-mod-fluentd

Apache fluentd module
C
6
star
19

php-password-hashing

PHP Password Hashing Command
C
5
star
20

phpman

PHP manual for command line
Shell
5
star
21

zmq-tools

ZeroMQ tools
C++
5
star
22

php-ext-elog

elog function Extension for PHP
C
5
star
23

php-ext-override

Override function Extension for PHP
C
5
star
24

php-ext-wiredtiger

C
5
star
25

php-ext-extension_load

PHP Extension load library
C
4
star
26

apache-mod-kafka

Kafka data collector module for Apache HTTPD Server
C
4
star
27

php-ext-callmap

Call a callback with an map of parameters function Extension for PHP
PHP
4
star
28

apache-mod-sundown

mod_sundown is Markdown handler module for Apache HTTPD Server.
C
4
star
29

zlmb

ZeroMQ-based Log Message broker
C
3
star
30

apache-mod-v8

mod_v8 is Javascript V8 Engine handler module for Apache HTTPD Server.
C++
3
star
31

php-ext-shellinford

PHP Extension for shellinford (FM-Index)
C
3
star
32

apache-mod-hoedown

mod_hoedown is Markdown handler module for Apache HTTPD Server
C
3
star
33

apache-mod-shorturl

mod_shorturl is mongoDB base shorturl module for Apache HTTPD Server.
C++
2
star
34

nginx-thumbhash

Nginx module for the ThumbHash
C
2
star
35

php-ext-xz

XZ Extension for PHP
PHP
2
star
36

php-ext-tink

Tink for PHP
C++
2
star
37

php-ext-transactd

PHP Extension for Transactd Plugin
C++
2
star
38

php-ext-enum

Enum interface
C
2
star
39

livereload-c

An implementation of the LiveReload server in C (libwebsocket)
C
2
star
40

nginx-jq

C
2
star
41

php-ext-bzip3

Bzip3 Extension for PHP
C
2
star
42

php-ext-extmethod

PHP extension is Extension method by closure.
PHP
1
star
43

nginx-qoi

C
1
star
44

fswatch

fswatch of notifytools use version.
C
1
star
45

php-ext-hidefl

Hidef lite function Extension for PHP
C
1
star
46

apache-mod-coffee

mod_coffee is CoffeeScript handler module for Apache HTTPD Server.
C
1
star
47

jq-api

API system with JSON files and jq filters
Shell
1
star
48

php-ext-brunsli

Brunsli Extension for PHP
C
1
star
49

mariadb-udf-php-password-hashing

PHP Password Hashing for MariaDB/MySQL UDF
C
1
star
50

woothee-c

The C implementation of Project Woothee
C
1
star