📄 filters.compression.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Compression Filters</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="filters.convert.html">Conversion Filters</a></div> <div class="next" style="text-align: right; float: right;"><a href="filters.encryption.html">Encryption Filters</a></div> <div class="up"><a href="filters.html">List of Available Filters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="filters.compression" class="section"> <h2 class="title">Compression Filters</h2> <p class="simpara"> While the <a href="wrappers.compression.html" class="link">Compression Wrappers</a> provide a way of creating gzip and bz2 compatible files on the local filesystem, they do not provide a means for generalized compression over network streams, nor do they provide a means to 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. </p> <blockquote><p><b class="note">Note</b>: <span class="simpara"> Compression filters do <em class="emphasis">not</em> generate headers and trailers used by command line utilities such as <i>gzip</i>. They only compress and decompress the payload portions of compressed data streams. </span> </p></blockquote> <p class="simpara"> <i>zlib.deflate</i> (compression) and <i>zlib.inflate</i> (decompression) are implementations of the compression methods described in <a href="http://www.faqs.org/rfcs/rfc1951" class="link external">» RFC 1951</a>. The <i>deflate</i> filter takes up to three parameters passed as an associative array. <i><tt class="parameter">level</tt></i> 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). <i><tt class="parameter">window</tt></i> 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 <i><tt class="parameter">window</tt></i> size is currently <b><tt>15</tt></b>. <i><tt class="parameter">memory</tt></i> 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. </p> <blockquote><p><b class="note">Note</b>: <span class="simpara"> Because compression level is the most commonly used parameter, it may be alternatively provided as a simple integer value (rather than an array element). </span> </p></blockquote> <p class="simpara"> zlib.* compression filters are available with PHP as of version <i>5.1.0</i> if <a href="ref.zlib.html" class="link">zlib</a> support is enabled. They are also available as a backport in version <i>5.0.x</i> by installing the <a href="http://pecl.php.net/package/zlib_filter" class="link external">» zlib_filter</a> package from <a href="http://pecl.php.net/" class="link external">» PECL</a>. These filters are <em class="emphasis">not</em> available for PHP 4. </p> <div class="example"> <p><b>Example #1 <i>zlib.deflate</i> and <i>zlib.inflate</i> </b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -