Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 12301

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Zlib Compression Functions</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="函数参考"
HREF="funcref.html"><LINK
REL="PREVIOUS"
TITLE="ZipArchive::unchangeName"
HREF="function.ziparchive-unchangename.html"><LINK
REL="NEXT"
TITLE="gzclose"
HREF="function.gzclose.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="reference"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.ziparchive-unchangename.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.gzclose.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="reference"
><A
NAME="ref.zlib"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
>CLXXXVIII. Zlib Compression Functions</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN251139"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.intro"
>简介</A
></H1
><P
>&#13;     This module enables you to transparently read and write
     gzip (.gz) compressed files, through versions of most of
     the <A
HREF="ref.filesystem.html"
>filesystem</A
> functions
     which work with gzip-compressed files (and uncompressed files,
     too, but not with sockets).
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
      Version 4.0.4 introduced a fopen-wrapper for .gz-files, so that
      you can use a special <TT
CLASS="filename"
>zlib:</TT
> URL to access
      compressed files transparently using the normal f*() file access
      functions if you prefix the filename or path with
      <TT
CLASS="filename"
>zlib:</TT
> when calling <A
HREF="function.fopen.html"
><B
CLASS="function"
>fopen()</B
></A
>. This
      feature requires a C runtime library that provides the
      <TT
CLASS="literal"
>fopencookie()</TT
> function. Up to now the GNU libc
      seems to be the only library that provides this feature.
     </P
><P
>&#13;      In PHP 4.3.0, <TT
CLASS="filename"
>zlib:</TT
> has been changed to
      <TT
CLASS="filename"
>compress.zlib://</TT
> to prevent ambiguities with
      filenames containing ':' characters. The
      <TT
CLASS="literal"
>fopencookie()</TT
> function is not longer required.
      More information is available in the section about
      <A
HREF="wrappers.compression.html"
>the 节 called <I
>压缩流</I
> 于 附录 N</A
>.
     </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.requirements"
>需求</A
></H1
><P
>&#13;     This module uses the functions of <A
HREF="http://www.gzip.org/zlib/"
TARGET="_top"
>zlib</A
>
     by Jean-loup Gailly and Mark Adler. You have to use a zlib
     version &#62;= 1.0.9 with this module.
    </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.installation"
>安装</A
></H1
><P
>&#13;  Zlib support in PHP is not enabled by default. You will need to
  configure PHP <CODE
CLASS="option"
>--with-zlib[=DIR]</CODE
>
 </P
><P
> <TT
CLASS="literal"
>PHP</TT
> 的 Windows
版本已经内置该扩展模块的支持。无需加载任何附加扩展库即可使用这些函数。</P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
   Built-in support for zlib on Windows is available with PHP 4.3.0.
  </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.configuration"
>运行时配置</A
></H1
><P
>这些函数的行为受 <TT
CLASS="filename"
>php.ini</TT
> 的影响。</P
><P
>&#13;  The zlib extension offers the option to transparently compress
  your pages on-the-fly, if the requesting browser supports
  this. Therefore there are three options in the <A
HREF="configuration.html#configuration.file"
>configuration file</A
> <TT
CLASS="filename"
>php.ini</TT
>.
   <DIV
CLASS="table"
><A
NAME="AEN251174"
></A
><P
><B
>表 1. Zlib Configuration Options</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><COL><THEAD
><TR
><TH
>Name</TH
><TH
>Default</TH
><TH
>Changeable</TH
><TH
>Changelog</TH
></TR
></THEAD
><TBODY
><TR
><TD
>zlib.output_compression</TD
><TD
>"0"</TD
><TD
>PHP_INI_ALL</TD
><TD
>Available since PHP 4.0.5.</TD
></TR
><TR
><TD
>zlib.output_compression_level</TD
><TD
>"-1"</TD
><TD
>PHP_INI_ALL</TD
><TD
>Available since PHP 4.3.0.</TD
></TR
><TR
><TD
>zlib.output_handler</TD
><TD
>""</TD
><TD
>PHP_INI_ALL</TD
><TD
>Available since PHP 4.3.0.</TD
></TR
></TBODY
></TABLE
></DIV
>
   有关 PHP_INI_* 常量进一步的细节与定义参见<A
HREF="ini.html"
>附录 H</A
>。
</P
><P
>以下是配置选项的简要解释。</P
><P
>&#13; <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><A
NAME="ini.zlib.output-compression"
></A
><CODE
CLASS="parameter"
>zlib.output_compression</CODE
>
    <A
HREF="language.types.boolean.html"
><B
CLASS="type"
>boolean</B
></A
>/<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
></DT
><DD
><P
>&#13;     Whether to transparently compress pages. If this option is set
     to "On" in <TT
CLASS="filename"
>php.ini</TT
> or the Apache configuration, pages are
     compressed if the browser sends an "Accept-Encoding: gzip" or
     "deflate" header. "Content-Encoding: gzip" (respectively
     "deflate") and "Vary: Accept-Encoding" headers are added to
     the output.
     In runtime, it can be set only before sending any output.
    </P
><P
>&#13;     This option also accepts integer values instead of boolean
     "On"/"Off", using this you can set the output buffer size
     (default is 4KB).
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
      <A
HREF="ref.outcontrol.html#ini.output-handler"
>output_handler</A
> must be 
      empty if this is set 'On' ! Instead you must use zlib.output_handler.
     </P
></BLOCKQUOTE
></DIV
></DD
><DT
><A
NAME="ini.zlib.output-compression-level"
></A
><CODE
CLASS="parameter"
>zlib.output_compression_level</CODE
>
    <A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
></DT
><DD
><P
>&#13;     Compression level used for transparent output compression.
    </P
></DD
><DT
><A
NAME="ini.zlib.output-handler"
></A
><CODE
CLASS="parameter"
>zlib.output_handler</CODE
>
    <A
HREF="language.types.string.html"
><B
CLASS="type"
>string</B
></A
></DT
><DD
><P
>&#13;     You cannot specify additional output handlers if zlib.output_compression
     is activated here. This setting does the same as <A
HREF="ref.outcontrol.html#ini.output-handler"
>&#13;     output_handler</A
> but in a different order.
    </P
></DD
></DL
></DIV
>
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.resources"
>资源类型</A
></H1
><P
>&#13;     This extension defines a file pointer resource returned by
     <A
HREF="function.gzopen.html"
><B
CLASS="function"
>gzopen()</B
></A
>.
    </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.constants"
>预定义常量</A
></H1
><P
>以下常量由本扩展模块定义,因此只有在本扩展模块被编译到
PHP 中,或者在运行时被动态加载后才有效。</P
><P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="constant"
><B
>FORCE_GZIP</B
></TT
> 
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;     
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>FORCE_DEFLATE</B
></TT
> 
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;     
    </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.examples"
>范例</A
></H1
><P
>&#13;     This example opens a temporary file and writes a test string 
     to it, then it prints out the content of this file twice.
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN251251"
></A
><P
><B
>例 1. Small Zlib Example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /><br />$filename </font><font color="#007700">= </font><font color="#0000BB">tempnam</font><font color="#007700">(</font><font color="#DD0000">'/tmp'</font><font color="#007700">, </font><font color="#DD0000">'zlibtest'</font><font color="#007700">) . </font><font color="#DD0000">'.gz'</font><font color="#007700">;<br />echo </font><font color="#DD0000">"&lt;html&gt;\n&lt;head&gt;&lt;/head&gt;\n&lt;body&gt;\n&lt;pre&gt;\n"</font><font color="#007700">;<br /></font><font color="#0000BB">$s </font><font color="#007700">= </font><font color="#DD0000">"Only a test, test, test, test, test, test, test, test!\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// open file for writing with maximum compression<br /></font><font color="#0000BB">$zp </font><font color="#007700">= </font><font color="#0000BB">gzopen</font><font color="#007700">(</font><font color="#0000BB">$filename</font><font color="#007700">, </font><font color="#DD0000">"w9"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// write string to file<br /></font><font color="#0000BB">gzwrite</font><font color="#007700">(</font><font color="#0000BB">$zp</font><font color="#007700">, </font><font color="#0000BB">$s</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// close file<br /></font><font color="#0000BB">gzclose</font><font color="#007700">(</font><font color="#0000BB">$zp</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// open file for reading<br /></font><font color="#0000BB">$zp </font><font color="#007700">= </font><font color="#0000BB">gzopen</font><font color="#007700">(</font><font color="#0000BB">$filename</font><font color="#007700">, </font><font color="#DD0000">"r"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// read 3 char<br /></font><font color="#007700">echo </font><font color="#0000BB">gzread</font><font color="#007700">(</font><font color="#0000BB">$zp</font><font color="#007700">, </font><font color="#0000BB">3</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// output until end of the file and close it.<br /></font><font color="#0000BB">gzpassthru</font><font color="#007700">(</font><font color="#0000BB">$zp</font><font color="#007700">);<br /></font><font color="#0000BB">gzclose</font><font color="#007700">(</font><font color="#0000BB">$zp</font><font color="#007700">);<br /><br />echo </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// open file and print content (the 2nd time).<br /></font><font color="#007700">if (</font><font color="#0000BB">readgzfile</font><font color="#007700">(</font><font color="#0000BB">$filename</font><font color="#007700">) != </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$s</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Error with zlib functions!"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">unlink</font><font color="#007700">(</font><font color="#0000BB">$filename</font><font color="#007700">);<br />echo </font><font color="#DD0000">"&lt;/pre&gt;\n&lt;/body&gt;\n&lt;/html&gt;\n"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>目录</B
></DT
><DT
><A
HREF="function.gzclose.html"
>gzclose</A
>&nbsp;--&nbsp;Close an open gz-file pointer</DT
><DT
><A
HREF="function.gzcompress.html"
>gzcompress</A
>&nbsp;--&nbsp;Compress a string</DT
><DT
><A
HREF="function.gzdecode.html"
>gzdecode</A
>&nbsp;--&nbsp;Decodes a gzip compressed string</DT
><DT
><A
HREF="function.gzdeflate.html"
>gzdeflate</A
>&nbsp;--&nbsp;Deflate a string</DT
><DT
><A
HREF="function.gzencode.html"
>gzencode</A
>&nbsp;--&nbsp;Create a gzip compressed string</DT
><DT
><A
HREF="function.gzeof.html"
>gzeof</A
>&nbsp;--&nbsp;Test for end-of-file on a gz-file pointer</DT
><DT
><A
HREF="function.gzfile.html"
>gzfile</A
>&nbsp;--&nbsp;Read entire gz-file into an array</DT
><DT
><A
HREF="function.gzgetc.html"
>gzgetc</A
>&nbsp;--&nbsp;Get character from gz-file pointer</DT
><DT
><A
HREF="function.gzgets.html"
>gzgets</A
>&nbsp;--&nbsp;Get line from file pointer</DT
><DT
><A
HREF="function.gzgetss.html"
>gzgetss</A
>&nbsp;--&nbsp;
   Get line from gz-file pointer and strip HTML tags
  </DT
><DT
><A
HREF="function.gzinflate.html"
>gzinflate</A
>&nbsp;--&nbsp;Inflate a deflated string</DT
><DT
><A
HREF="function.gzopen.html"
>gzopen</A
>&nbsp;--&nbsp;Open gz-file</DT
><DT
><A
HREF="function.gzpassthru.html"
>gzpassthru</A
>&nbsp;--&nbsp;
   Output all remaining data on a gz-file pointer
  </DT
><DT
><A
HREF="function.gzputs.html"
>gzputs</A
>&nbsp;--&nbsp;别名 <A
HREF="function.gzwrite.html"
><B
CLASS="function"
>gzwrite()</B
></A
></DT
><DT
><A
HREF="function.gzread.html"
>gzread</A
>&nbsp;--&nbsp;Binary-safe gz-file read</DT
><DT
><A
HREF="function.gzrewind.html"
>gzrewind</A
>&nbsp;--&nbsp;Rewind the position of a gz-file pointer</DT
><DT
><A
HREF="function.gzseek.html"
>gzseek</A
>&nbsp;--&nbsp;Seek on a gz-file pointer</DT
><DT
><A
HREF="function.gztell.html"
>gztell</A
>&nbsp;--&nbsp;Tell gz-file pointer read/write position</DT
><DT
><A
HREF="function.gzuncompress.html"
>gzuncompress</A
>&nbsp;--&nbsp;Uncompress a compressed string</DT
><DT
><A
HREF="function.gzwrite.html"
>gzwrite</A
>&nbsp;--&nbsp;Binary-safe gz-file write</DT
><DT
><A
HREF="function.readgzfile.html"
>readgzfile</A
>&nbsp;--&nbsp;Output a gz-file</DT
><DT
><A
HREF="function.zlib-get-coding-type.html"
>zlib_get_coding_type</A
>&nbsp;--&nbsp;Returns the coding type used for output compression</DT
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.ziparchive-unchangename.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.gzclose.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>ZipArchive::unchangeName</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="funcref.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>gzclose</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>