I'm using php's file_get_contents()
function to do a HTTP request. To save bandwidth I decided to add the "Accept-Encoding: gzip"
header using stream_context_create()
.
Obviously, file_get_contents()
outputs a gzip encoded string so I'm using gzuncompress()
to decode the encoded string but I get an error with data passed as argument.
[...] PHP Warning: gzuncompress(): data error in /path/to/phpscript.php on line 26
I know there is another function able to decompress gzipped data gzdecode()
but it isn't included in my PHP version (maybe it is only available on SVN).
I know that cUrl decodes gzip stream on the fly (without any problem) but someone suggested me to use file_get_contents()
instead of cUrl.
Do you know any other way to decompress gzipped data in PHP or why gzuncompress()
outputs a Warning? It is absurd that gzuncompress()
doesn't work as expected.
Notes:
The problem is certainly about PHP: the HTTP request is made to Tumblr API that give a well-encoded response.