HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

deflate_init

Description

The deflate_init of zlib for PHP initializes an incremental deflate context.

Syntax

deflate_init(
    int $encoding,
    array $options = []
): DeflateContext|false

Parameters

encoding

One of the ZLIB_ENCODING_* constants.

ConstantDescription
ZLIB_ENCODING_RAWDEFLATE algorithm as per RFC 1951.
ZLIB_ENCODING_DEFLATEZLIB compression algorithm as per RFC 1950.
ZLIB_ENCODING_GZIPGZIP algorithm as per RFC 1952.

options

An associative array which may contain the following elements:

level

The compression level.

Range is from -1 to 9. Default is -1.

memory

The compression memory level.

Range is from 1 to 9. Default is 8.

window

The zlib window size (logarithmic).

Range is from 8 to 15. Default is 15.

zlib changes a window size of 8 to 9, and as of zlib 1.2.8 fails with a warning, if a window size of 8 is requested for ZLIB_ENCODING_RAW or ZLIB_ENCODING_GZIP.

strategy

One of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED or ZLIB_DEFAULT_STRATEGY (default).

dictionary

A string or an array of strings of the preset dictionary (default: no preset dictionary).

Return

Returns a deflate context resource (zlib.deflate) on success, or false on failure.

Examples

1 · encoding · ZLIB_ENCODING_RAW

<?

$encoding = ZLIB_ENCODING_RAW;

$return = deflate_init($encoding);

var_dump($return);
object(DeflateContext)#1 (0) {
}

2 · encoding · ZLIB_ENCODING_DEFLATE

<?

$encoding = ZLIB_ENCODING_DEFLATE;

$return = deflate_init($encoding);

var_dump($return);
object(DeflateContext)#1 (0) {
}

3 · encoding · ZLIB_ENCODING_GZIP

<?

$encoding = ZLIB_ENCODING_GZIP;

$return = deflate_init($encoding);

var_dump($return);
object(DeflateContext)#1 (0) {
}

4 · options

<?

$encoding = ZLIB_ENCODING_DEFLATE;
$options =
[
    "level" => -1,
    "memory" => 8,
    "window" => 15,
    "strategy" => ZLIB_DEFAULT_STRATEGY,
    "dictionary" => "",
];

$return = deflate_init($encoding, $options);

var_dump($return);
object(DeflateContext)#1 (0) {
}