diff --git a/appendices/filters.xml b/appendices/filters.xml index a9b92e3298..66c363995b 100644 --- a/appendices/filters.xml +++ b/appendices/filters.xml @@ -1,7 +1,7 @@ - + - List of Built-In Filters + List of Available Filters The following is a list of a few built-in stream filters for use with stream_filter_append. @@ -229,6 +229,132 @@ fwrite($fp, "This is a test.\n"); +
+ Compression Filters + + + While the provide a way of creating + gzip and bz2 compatable files on the local filesystem, they do not provide a + means for generalized compression over network streams, nor do they provide a + means begin with a non-compressed stream and transition to a compressed one. + For this, a compression filter may be applied to any stream resource at any time. + + + + + Compression filters do not generate headers and trailers + used by commandline utilites such as gzip. They only compress + and decompress the payload portions of compressed data streams. + + + + + zlib.deflate (compression) and + zlib.inflate (decompression) are implementations of + the compression methods described in RFC 1951. + The deflate filter takes up to three parameters passed as + an associative array. + + level describes the compression + strength to use (1-9). Higher numbers will generally yield smaller payloads at + the cost of additional processing time. Two special compression levels also exist: + 0 (for no compression at all), and -1 (zlib internal default -- currently 6). + + window is the base-2 log of the compression loopback window size. + Higher values (up to 15 -- 32768 bytes) yield better compression at a cost of memory, + while lower values (down to 9 -- 512 bytes) yield worse compression in a smaller memory footprint. + Default window size is currently 15. + + memory is a scale indicating how much work memory should be allocated. + Valid values range from 1 (minimal allocation) to 9 (maximum allocation). This memory allocation + affects speed only and does not impact the size of the generated payload. + + + + + Because compression level is the most commonly used parameter, it may be alternatively + provided as a simple integer value (rather than an array element). + + + + + + The zlib.* filters are not currently built into the PHP core. To enable these filters + in PHP 5, install the zlib_filter + package from PECL. These filters are not + available for PHP 4. + + + + + + <literal>zlib.deflate</literal> and + <literal>zlib.inflate</literal> + + + 6, 'window' => 15, 'memory' => 9); + +$original_text = "This is a test.\nThis is only a test.\nThis is not an important string.\n"; +echo "The original text is " . strlen($original_text) . " characters long.\n"; + +$fp = fopen('test.deflated', 'w'); +stream_filter_append($fp, 'zlib.deflate', STREAM_FILTER_WRITE, $params); +fwrite($fp, $original_text); +fclose($fp); + +echo "The compressed file is " . filesize('test.deflated') . " bytes long.\n"; +echo "The original text was:\n"; +/* Use readfile and zlib.inflate to decompress on the fly */ +readfile('php://filter/zlib.inflate/resource=test.deflated'); + +/* Generates output: + +The original text is 70 characters long. +The compressed file is 56 bytes long. +The original text was: +This is a test. +This is only a test. +This is not an important string. + + */ +?> +]]> + + + + + + <literal>zlib.deflate</literal> simple + + + +]]> + + + +
+