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.
gzopen
(PHP 4, PHP 5)
gzopen — gz ファイルを開く
説明
resource gzopen ( string filename, string mode [, int use_include_path] )読み込みもしくは書き込みのために gzip (.gz) ファイルをオープンします。
gzopen() は、gzip フォーマットでないファイルの読み込みについても使用することができます。 この場合、gzread()は、ファイルを解凍せずに直接読み 込まれます。
パラメータ
- filename
ファイル名を指定します
- mode
fopen() と同じ (rb または wb) ですが、 圧縮レベル (wb9) または圧縮の方策、 つまり、wb6f のようにフィルターを通したデータを f で指定したり、h でハフマン圧縮のみを行うことを指定したりすることができます。 (方策に関するパラメータの詳細については、zlib.h の中の deflateInit2 の説明を参照ください。)
- use_include_path
このオプションパラメータを 1 にすることにより、 include_pathにあるファイルも 検索することができます。
返り値
オープンしたファイルへのファイルポインタを返します。その後、 このファイルディスクプリタから読み込んだ全ては透過的に解凍され、 書き込んだものは圧縮されます。
オープンに失敗した場合、この関数は FALSE を返します。
例
参考
| gzclose() |
gzopen
rob at digital-crocus dot com
01-Jun-2005 09:28
01-Jun-2005 09:28
pentek_imre at mailbox dot hu
30-Jan-2005 03:36
30-Jan-2005 03: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
22-Oct-2004 04:04
22-Oct-2004 04: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
03-Jan-2002 12:22
03-Jan-2002 12: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...