php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28051 gzip accept-encoding for HTTP request
Submitted: 2004-04-19 03:12 UTC Modified: 2005-02-05 11:50 UTC
Votes:7
Avg. Score:4.4 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:1 (16.7%)
From: Olaf at XCC dot TMFWeb dot NL Assigned: pollita (profile)
Status: Suspended Package: Feature/Change Request
PHP Version: 5 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Olaf at XCC dot TMFWeb dot NL
New email:
PHP Version: OS:

 

 [2004-04-19 03:12 UTC] 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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-19 06:35 UTC] pollita@php.net
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.
 [2005-02-05 08:50 UTC] 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
i4n3fo@byte45shift.de
(del numbers to despam)
 [2005-02-05 11:50 UTC] Olaf at XCC dot TMFWeb dot NL
> (lest I didn't get the point...)

The point is gzip suppport in file_get_contents().
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC