How to file_get_contents a gzip page ? |
[eluser]Benjamin David[/eluser]
Hi ! I'm trying to get the content of a page that has gzip header compression. When I file_get_contents the page, the result is compressed and I can't find a way to get the original content, uncompressed. I've tried the gzdeflate and gzuncompress php 5 function and it didn't work. I haven't tried the gzdecode function as it comes with PHP 6 and my host hasn't it yet. The page I'm trying to get content from is there : http://ax.phobos.apple.com.edgesuite.net...on&limit=1 And it's killing me because I can make it work in Javascript with Ajax requests because the browser automaticaly uncompresses the whole thing but not with PHP... Too bad ! Thanks for helping !
[eluser]pistolPete[/eluser]
This problem is described here plus a workaround is suggested: http://bugs.php.net/bug.php?id=22967 But there are other possibilities: Try to send a HTTP request without Code: Accept-Encoding: gzip Alternatively you could use cURL: Code: curl_setopt($handle,CURLOPT_ENCODING , 'gzip'); Or use one of the user contributed gzdecode() functions here: http://php.net/gzencode
[eluser]Benjamin David[/eluser]
Thanks for your answer ! It's giving me hope ![]() I'm gonna test them and I'll hopefully write back the final word so it can help others that are trying to use Apple API.
[eluser]Benjamin David[/eluser]
The user contributed gzdecode() function you were talking about works perfectly ! Thanks a lot pistolPete ! So here's the function I used to get decode a gziped string (found there : http://php.net/gzencode) : Code: <?php
[eluser]digitalpbk[/eluser]
Thanks for this information, I had a problem similarly while using file_get_contents which returned me gzip contents and I had to unzip. See more details file_get_contents gzip uncompress |
Welcome Guest, Not a member yet? Register Sign In |