Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Zlib Compression Functions : gzopen

gzopen

Open gz-file (PHP 4, PHP 5)
resource gzopen ( string filename, string mode [, int use_include_path] )

Example 2730. gzopen() Example

<?php
$fp
= gzopen("/tmp/file.gz", "r");
?>

Code Examples / Notes » gzopen

dtorop932

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");
?>


rob

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

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.

-delete-this-part-dubious

"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...


Change Language


Follow Navioo On Twitter
gzclose
gzcompress
gzdecode
gzdeflate
gzencode
gzeof
gzfile
gzgetc
gzgets
gzgetss
gzinflate
gzopen
gzpassthru
gzputs
gzread
gzrewind
gzseek
gztell
gzuncompress
gzwrite
readgzfile
zlib_get_coding_type
eXTReMe Tracker