2

I'd like to make a cURL request that accepts a gzip'ed page. I would then like to unzip the page and process it. I haven't been able to find any ready built examples, so I would like a quick one. Any settings that need to be adjusted, making the actual request, and decompressing the contents.

2 Answers 2

5

You can request a gzipped encoding with curl_setopt, like this:

curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); 

You can then decompress the content with gzdecode like this:

$response = gzdecode($response);
3
  • By gzdecode did you mean this short function? Is there any benefit to using the longer and more complicated looking one?
    – Josh K
    Commented Apr 10, 2010 at 1:06
  • by gzdecode, I mean the actual gzdecode function built into PHP. This function is part of PHP, you can just call it. The functions you pointed out are functions that other people have made to do other stuff in addition to unzipping the content.
    – Kibbee
    Commented Apr 10, 2010 at 1:11
  • I actually received an error when I just tried to call the gzdecode function, hence the search.
    – Josh K
    Commented Apr 10, 2010 at 3:26
1

Question duplicated at Uncompress a gzip file from CURL, on php. It says that response can be automatically decoded using

curl_setopt($ch,CURLOPT_ENCODING, 1);

Not the answer you're looking for? Browse other questions tagged or ask your own question.