PHP ʖ²ἯTH
º/A
CXIII. Zlib Compression Functions
½鉜
This module enables you to transparently read and write gzip (.gz) compressed files, through versions of most of the filesystem functions which work with gzip-compressed files (and uncompressed files, too, but not with sockets).
ע: 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 fopen().
In version 4.3.0, this special prefix has been changed to 'zlib://' to prevent ambiguities with filenames containing ':'.
This feature requires a C runtime library that provides the fopencookie() function. To my current knowledge the GNU libc is the only library that provides this feature.
Шdz
This module uses the functions of zlib by Jean-loup Gailly and Mark Adler. You have to use a zlib version = 1.0.9 with this module.
°²װ
Zlib support in PHP is not enabled by default. You will need to configure PHP --with-zlib[=DIR]
PHP µĠWindows °汾ґ¾Ěփ¸À©չģ¿鵄֧³֡£ĺΞШ¼Ӕ؈κθ½¼ӵĀ©չ¿⼴¿Ɋ¹ӃբЩº¯ʽ¡£
ע: Builtin support for zlib is available with PHP 4.3.0.
ԋАʱŤփ
բЩº¯ʽµĐЎªʜµ½ȫ¾ּA HREF="configuration.html#configuration.file" Ťփ΄¼þ php.ini µē°Ϭ¡£
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 configuration file php.ini.
Name
Default
Changeable
zlib.output_compression
"Off"
PHP_INI_ALL
zlib.output_compression_level
"-1"
PHP_INI_ALL
zlib.output_handler
""
PHP_INI_ALL
Whether to transparently compress pages. If this option is set to "On" in php.ini 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.
You can use ini_set() 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.
This option also accepts integer values instead of boolean "On"/"Off", using this you can set the output buffer size (default is 4KB).
ע: output_handler must be empty if this is set 'On'! Instead you must use zlib.output_handler.
Compression level used for transparent output compression.
You cannot specify additional output handlers if zlib.output_compression is activated here. This setting does the same as output_handler but in a different order.
Դ Ѝ
¸À©չģ¿鎴¶¨ҥȎºΗʔ´ Ѝ¡£
Ԥ¶¨ҥ³£
·¶=
This example opens a temporary file and writes a test string to it, then it prints out the content of this file twice.
=ד 1. Small Zlib Example
?php $filename = tempnam ('/tmp', 'zlibtest').'.gz'; print "html \n head /head \n body \n pre \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" /pre \n /h1 /body \n /html \n";?
Ŀ¼ gzclose -- Close an open gz-file pointer gzcompress -- Compress a string gzdeflate -- Deflate a string gzencode -- Create a gzip compressed string gzeof -- Test for end-of-file on a gz-file pointer gzfile -- Read entire gz-file into an array gzgetc -- Get character from gz-file pointer gzgets -- Get line from file pointer gzgetss -- Get line from gz-file pointer and strip HTML tags gzinflate -- Inflate a deflated string gzopen -- Open gz-file gzpassthru -- Output all remaining data on a gz-file pointer gzputs -- Write to a gz-file pointer gzread -- Binary-safe gz-file read gzrewind -- Rewind the position of a gz-file pointer gzseek -- Seek on a gz-file pointer gztell -- Tell gz-file pointer read/write position gzuncompress -- Uncompress a deflated string gzwrite -- Binary-safe gz-file write readgzfile -- Output a gz-file
º/A
ưµ㼯A
zip_read
ɏһ¼¶
gzclose