WARNING gzopen and gzread have a major disadvantage. They makes NO checksum and NO length verification of the gzipped data and discard this valuable information. This should be documented here.
gzopen
(PHP 4, PHP 5)
gzopen — .gz파일을 연다
Description
int gzopen
( string $filename
, string $mode
[, int $
use_include_path
] )
gzip (.gz)파일을 읽기 또는 쓰기위해 연다. mode 파라미터는 fopen() ("rb" or "wb")와 같고, 또한 압축레벨 ("wb9") 또는 stategy를 포함한다: 'f' for filtered data as in "wb6f", 'h' for Huffman only compression as in "wb1h". (strategy parameter에 관한 보다 많은 정보를 원한다면 the description of deflateInit2 in zlib.h보라.)
gzopen()은 gzip 포멧이 아닌 파일을 읽는데 사용될 수 있다.; 이 경우 gzread()로 압축해제 없이 바로 파일로 부터 읽을 수 있다.
gzopen()은 열고자 지정한 파일을 리턴 한다. 그리고는 읽고자 하는 모든것을 압축해제하고, 기록하고 압축할 수 있다.
만일 열기에 실패하면 FALSE를 리턴한다.
세번째 옵션의 파라미터에 "1"을 넣으면 include_path안의 파일을 검색 할수 있다.
Example#1 gzopen() Example
$fp = gzopen ("/tmp/file.gz", "r");
참고 gzclose().
gzopen
katzlbtjunk at hotmail dot com
23-Apr-2008 12:15
23-Apr-2008 12:15
rob at digital-crocus dot com
01-Jun-2005 05:28
01-Jun-2005 05:28
dtorop932 at hotmail dot com's comments, according to my tests, is incorrect. That code wishes to download the entire file before parsing, which is inconvinient. The wget method works though.
pentek_imre at mailbox dot hu
29-Jan-2005 10:36
29-Jan-2005 10:36
Be aware that when opening a remote file on a http server the gzopen will return by default false after 120 seconds waiting to any answer.
dtorop932 at hotmail dot com
21-Oct-2004 12:04
21-Oct-2004 12:04
RE dubious's comment: "Being able to read gzip streams from ftp and http is near the top of my personal wishlist at the moment..."
One way to read a gzip stream over http is to daisychain stream wrappers, e.g.:
<?
$fp = fopen("compress.zlib://http://some.website.org/example.gz", "r");
?>
-delete-this-part-dubious at 2xtreme dot net
02-Jan-2002 07:22
02-Jan-2002 07:22
"On the fly" gunzipping actually DOES seem to work - it just appears that only LOCAL streams/files (including php://stdin) can be accessed for some reason. I THINK (but have not yet tested) that you could similarly gzopen "php://stdout" and pass a stream of gzipped data to the browser (when run from a web page) or console (when run standalone) through there.
I HAVE tested scripts from the command line like:
wget -q -O- ftp://some.host.net/pub/some_gzip_file.gz | php gunzip_stuff.php
where gunzip_stuff.php would be a script that gzopened "php://stdin" and did gzgets from that stream, and it seems to work fine, but that obviously doesn't help someone wanting to grab gzipped streams from remote sites from a web-based script.
Being able to read gzip streams from ftp and http is near the top of my personal wishlist at the moment...
