|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 01:00:01 2025 UTC |
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)