#28051 [Sus]: gzip accept-encoding for HTTP request

From: Date: Sat, 05 Feb 2005 10:50:55 +0000
Subject: #28051 [Sus]: gzip accept-encoding for HTTP request
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-73506@lists.php.net to get a copy of this message
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 i4n3fo@byte45shift.de (del numbers to despam) ------------------------------------------------------------------------ [2004-04-19 06:35:47] 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#73506) next »