Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 3157

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>Zlib Compression Functions</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Function Reference"
HREF="funcref.html"><LINK
REL="PREVIOUS"
TITLE="zip_read"
HREF="function.zip-read.html"><LINK
REL="NEXT"
TITLE="gzclose"
HREF="function.gzclose.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></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 Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.zip-read.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.gzclose.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="reference"
><A
NAME="ref.zlib"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
>CXIII. Zlib Compression Functions</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN98820"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.intro"
></A
>Introduction</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
>Note: </B
>
      Version 4.0.4 introduced a fopen-wrapper for .gz-files, so that
      you can use a special 'zlib:' URL to access compressed files
      transparently using the normal f*() file access functions if you
      prepend the filename or path with a 'zlib:' prefix when calling
      <A
HREF="function.fopen.html"
><B
CLASS="function"
>fopen()</B
></A
>.
     </P
><P
>&#13;      In version 4.3.0, this special prefix has been changed to 'zlib://'
      to prevent ambiguities with filenames containing ':'.
     </P
><P
>&#13;      This feature requires a C runtime library that provides the
      <TT
CLASS="literal"
>fopencookie()</TT
> function. To my current
      knowledge the GNU libc is the only library that provides
      this feature.
     </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.requirements"
></A
>Requirements</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
>Installation</H1
><P
>&#13;  Zlib support in PHP is not enabled by default. You will need to
  configure PHP <TT
CLASS="option"
>--with-zlib[=DIR]</TT
>
 </P
><P
> The windows version of <TT
CLASS="literal"
>PHP</TT
>
has built in support for this extension. You do not need to load any additional
extension in order to use these functions.</P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
   Builtin support for zlib is available with PHP 4.3.0.
  </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.configuration"
></A
>Runtime Configuration</H1
><P
>&#13;The behaviour of these functions is affected by settings in <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="AEN98850"
></A
><P
><B
>Table 1. Zlib Configuration Options</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Name</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Default</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Changeable</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>zlib.output_compression</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>"Off"</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PHP_INI_ALL</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>zlib.output_compression_level</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>"-1"</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PHP_INI_ALL</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>zlib.output_handler</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>""</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PHP_INI_ALL</TD
></TR
></TBODY
></TABLE
></DIV
>
   For further details and definition of the PHP_INI_* constants see
  <A
HREF="function.ini-set.html"
><B
CLASS="function"
>ini_set()</B
></A
>.
</P
><P
>&#13; Here is a short explanation of the configuration directives.
 <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><A
NAME="ini.zlib.output-compression"
></A
><TT
CLASS="parameter"
><I
>zlib.output_compression</I
></TT
>
    <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.
    </P
><P
>&#13;     You can use <A
HREF="function.ini-set.html"
><B
CLASS="function"
>ini_set()</B
></A
> to disable this in
     your script if the headers aren't already sent. If you output
     a "Content-Type: image/" header the compression is disabled,
     too (in order to circumvent a Netscape bug). You can reenable
     it, if you add "ini_set('zlib.output_compression', 'On')"
     after the header call which added the image content-type.
    </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
>Note: </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
><TT
CLASS="parameter"
><I
>zlib.output_compression_level</I
></TT
>
    <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
><TT
CLASS="parameter"
><I
>zlib.output_handler</I
></TT
>
    <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
>Resource Types</H1
><P
>This extension has no resource types defined.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.constants"
></A
>Predefined Constants</H1
><P
>&#13;The constants below are defined by this extension, and
will only be available when the extension has either
been compiled into PHP or dynamically loaded at runtime.
</P
><P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="constant"
><B
>FORCE_GZIP</B
></TT
> 
    (<A
HREF="language.types.integer.html"
>integer</A
>)</DT
><DD
><P
>&#13;     
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>FORCE_DEFLATE</B
></TT
> 
    (<A
HREF="language.types.integer.html"
>integer</A
>)</DT
><DD
><P
>&#13;     
    </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="zlib.examples"
></A
>Examples</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="AEN98923"
></A
><P
><B
>Example 1. Small Zlib Example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

$filename = tempnam ('/tmp', 'zlibtest').'.gz';
print "&#60;html&#62;\n&#60;head&#62;&#60;/head&#62;\n&#60;body&#62;\n&#60;pre&#62;\n";
$s = "Only a test, test, test, test, test, test, test, test!\n";

// open file for writing with maximum compression
$zp = gzopen($filename, "w9");

// write string to file
gzwrite($zp, $s);

// close file
gzclose($zp);

// open file for reading
$zp = gzopen($filename, "r");

// read 3 char
print gzread($zp, 3);

// output until end of the file and close it.
gzpassthru($zp);

print "\n";

// open file and print content (the 2nd time).
if (readgzfile($filename) != strlen($s)) {
        echo "Error with zlib functions!";
}
unlink($filename);
print "&#60;/pre&#62;\n&#60;/h1&#62;&#60;/body&#62;\n&#60;/html&#62;\n";

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</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.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;Write to a gz-file pointer</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 deflated 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
></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.zip-read.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.gzclose.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>zip_read</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="funcref.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>gzclose</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>