ID:               28051
 User updated by:  Olaf at XCC dot TMFWeb dot NL
 Reported By:      Olaf at XCC dot TMFWeb dot NL
 Status:           Suspended
 Bug Type:         Feature/Change Request
 Operating System: *
-PHP Version:      4.3.6
+PHP Version:      5
 Assigned To:      pollita
 New Comment:

> (lest I didn't get the point...)

The point is gzip suppport in file_get_contents().


Previous Comments:
------------------------------------------------------------------------

[2005-02-05 08:50:43] none at none dot org

I get the desired result like this:
(lest I didn't get the point...)

<?php

  //  my server sends gzipped data if client allows
  $url = "www.byteshift.de";

  function gzdecode($string){
    $string = substr($string, 10);
    return gzinflate($string);
  }

  function get_gzipped_data($url){
    $http_response = '';
    $fp = fsockopen($url, 80);
    fputs($fp, "GET / HTTP/1.1\r\n");
    fputs($fp, "Accept-Encoding: gzip\r\n");
  
    fputs($fp, "Host: $url\r\n\r\n");
    while (!feof($fp))
      $http_response .= fgets($fp, 128);
    fclose($fp);
    return $http_response;
  }

  preg_match("/^(.+)\r?\n\r?\n\w+\r?\n(.+)$/s",
             get_gzipped_data($url),
             $matches);
  $header = $matches[1];
  $body   = $matches[2];
  $html   = gzdecode($body);
        $strlen_uncomp = strlen(file_get_contents("http://$url/";));
        $strlen_decomp = strlen($body);

  echo "
  strlen_uncomp: $strlen_uncomp Kb
  strlen_decomp: $strlen_decomp Kb
  =============================
  $html
  ";
?>

Marek Moehling
byteshift.de
[EMAIL PROTECTED]
(del numbers to despam)

------------------------------------------------------------------------

[2004-04-19 06:35:47] [EMAIL PROTECTED]

This may be added in PHP 5.1.

In the mean time you may be able to acheive this behavior using a
combination of the header context parameter for the http:// wrapper and
the zlib_filter found in PECL.  This stop-gap solution will only work in
PHP5 however.

------------------------------------------------------------------------

[2004-04-19 03:12:35] Olaf at XCC dot TMFWeb dot NL

Description:
------------
This code sends a HTTP request without gzip accept-encoding header, so
the server can't send a gzip content encoded response.

Reproduce code:
---------------
<?php
        echo strlen(file_get_contents("http://php.net/";));
?>


Expected result:
----------------
GET /s HTTP/1.0
Content-Encoding: gzip
Host: php.net

HTTP/1.0 200 OK
Content-Type: text/plain



Actual result:
--------------
GET /s HTTP/1.0
Host: php.net

HTTP/1.0 200 OK
Content-Type: text/plain




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=28051&edit=1

Reply via email to