Results 1 to 2 of 2
  1. #1

    PHP GZIP Decoding?

    Hello all, I have been told that I need to add 'Accept-Encoding: compress, gzip' to the header when I retrieve an xml feed. I ended up using...

    Code:
    <?php
    
    $cmd='curl -H \"Accept-Encoding: compress, gzip\" http://thesite.com/xmlfile.xml';
    
    exec($cmd,$results);
    
    print_r($results);
    ?>
    This prints the array with the encoded gzip text but I can't seem to decode it, how do I go about that or what is the proper way to do this?

    Thanks.

  2. #2
    Join Date
    Mar 2007
    Location
    UK
    Posts
    89
    Presumably you have been told to do this to reduce bandwidth usage, and increase the speed of your download?

    Try playing with the CURLOPT_ENCODING option: this will make cURL decompress the content automatically:
    http://curl.haxx.se/libcurl/c/curl_e...URLOPTENCODING
    CURLOPT_ENCODING

    Sets the contents of the Accept-Encoding: header sent in an HTTP request, and enables decoding of a response when a Content-Encoding: header is received. Three encodings are supported: identity, which does nothing, deflate which requests the server to compress its response using the zlib algorithm, and gzip which requests the gzip algorithm. If a zero-length string is set, then an Accept-Encoding: header containing all supported encodings is sent.

    This is a request, not an order; the server may or may not do it. This option must be set (to any non-NULL value) or else any unsolicited encoding done by the server is ignored. See the special file lib/README.encoding for details.
    Incidentally, unless there is a compelling reason not to do so, I would use php's curl functions rather than shelling out and running the cURL binary.


    HTH,

    Simon

Similar Threads

  1. Need some help decoding (If possible)
    By ThatScriptGuy in forum Programming Discussion
    Replies: 6
    Last Post: 10-27-2009, 10:07 AM
  2. mod gzip and php obgzhandler
    By sexshun in forum Hosting Security and Technology
    Replies: 0
    Last Post: 10-23-2005, 12:09 AM
  3. Turck MMCACHE GZIP problem (apache, php)
    By bigfoo in forum Hosting Security and Technology
    Replies: 3
    Last Post: 09-17-2004, 09:04 AM
  4. PHP Help: Encoding/Decoding characters
    By zahid in forum Programming Discussion
    Replies: 2
    Last Post: 05-30-2004, 03:18 PM
  5. PHP Mime decoding help
    By aah-jim in forum Programming Discussion
    Replies: 6
    Last Post: 09-21-2003, 09:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •