473,943 Members | 23,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trouble measuring filesize of gzipped data

My server (Apache/1.3.28 - PHP/4.3.3)
is configured to receive gzipped data via:
Header append Accept-Encoding "gzip, deflate"

PHP is configured to send gzipped data via:
php_value output_handler ob_gzhandler

When downloading files from servers that send gzipped data as well,
I'd like to get the filesize before and after my server decompresses them.

=============== =============== ==============
// same result with fopen()
$file = file_get_conten ts("http://someUrl");
=============== =============== ==============

strlen($file) yields the decompressed filesize, however.
How can I measure the filesize of the compressed data?
Anyone any idea?
Marek

bn*****@g214mx. net
(remove numbers to despam)
Jul 17 '05 #1
4 2642
"Marek Möhling" <no****@nospam. org> wrote in
news:cu******** *****@news.t-online.com:
My server (Apache/1.3.28 - PHP/4.3.3)
is configured to receive gzipped data via:
Header append Accept-Encoding "gzip, deflate"

PHP is configured to send gzipped data via:
php_value output_handler ob_gzhandler

When downloading files from servers that send gzipped data as well,
I'd like to get the filesize before and after my server decompresses
them.

=============== =============== ==============
// same result with fopen()
$file = file_get_conten ts("http://someUrl");
=============== =============== ==============

strlen($file) yields the decompressed filesize, however.
How can I measure the filesize of the compressed data?


This won't be 100% accurate, but you could estimate the gzipped size
using:

strlen(gzcompre ss($file));

Also, an "I'm not sure that does what you think it does" note. The Apache
directive only applies when people are requesting web pages from your
server. This is good, and can save you some bandwidth, but it doesn't have
any effect on your PHP scripts when they download remote files. Your
scripts are downloading the raw, uncompressed data.

hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Jul 17 '05 #2
> This won't be 100% accurate, but you could estimate the gzipped size
using:
strlen(gzcompre ss($file));
Thanks governor, an obvious solution, I was sitting on my brains...-) I
guess.
Then again, this would give a false result when the remote server was
sending uncompressed data.
Also, an "I'm not sure that does what you think it does" note. The Apache
directive only applies when people are requesting web pages from your
server. This is good, and can save you some bandwidth, but it doesn't have
any effect on your PHP scripts when they download remote files. Your
scripts are downloading the raw, uncompressed data.
IMO when the remote server is configured to sent compressed data,
that's what
a) my server
b) my PHP script
get. I guess that my server handles the decoding and
passes it to my script.

http://web-sniffer.net
detects correctly wether a server uses compression or not.
I checked it by requesting my domain with:
"php_value output_handler ob_gzhandler"
set and unset by htaccess.

So somehow it's possible...
I guess that opening a socket myself using PEAR:Net would be needed,
(bypassing file_get_conten ts and it ilk) but I can't figure out the
details.


Marek

bn*****@g214mx. net
(remove numbers to despam)



"Senator Jay Billington Bulworth" <f@fung.arg> wrote in message
news:Xn******** *************** **@65.24.7.150. .. "Marek Möhling" <no****@nospam. org> wrote in
news:cu******** *****@news.t-online.com:
My server (Apache/1.3.28 - PHP/4.3.3)
is configured to receive gzipped data via:
Header append Accept-Encoding "gzip, deflate"

PHP is configured to send gzipped data via:
php_value output_handler ob_gzhandler

When downloading files from servers that send gzipped data as well,
I'd like to get the filesize before and after my server decompresses
them.

=============== =============== ==============
// same result with fopen()
$file = file_get_conten ts("http://someUrl");
=============== =============== ==============

strlen($file) yields the decompressed filesize, however.
How can I measure the filesize of the compressed data?


This won't be 100% accurate, but you could estimate the gzipped size
using:

strlen(gzcompre ss($file));

Also, an "I'm not sure that does what you think it does" note. The Apache
directive only applies when people are requesting web pages from your
server. This is good, and can save you some bandwidth, but it doesn't have
any effect on your PHP scripts when they download remote files. Your
scripts are downloading the raw, uncompressed data.

hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources



Jul 17 '05 #3
"Marek Möhling" <no****@nospam. org> wrote in
news:cu******** *****@news.t-online.com:
Also, an "I'm not sure that does what you think it does" note. The Apache directive only applies when people are requesting web pages from your server. This is good, and can save you some bandwidth, but it doesn't have any effect on your PHP scripts when they download remote files. Your scripts are downloading the raw, uncompressed data.
IMO when the remote server is configured to sent compressed

data, that's what
a) my server
b) my PHP script
get. I guess that my server handles the decoding and
passes it to my script.
It's sort of the other way around. When your script sends a
request to
another website, that request isn't coming from Apache, it's
coming from
PHP. PHP then sends the result of your script to Apache, and
Apache
sends it to your web browser.
So somehow it's possible...
I guess that opening a socket myself using PEAR:Net would be needed, (bypassing file_get_conten ts and it ilk) but I can't figure out the details.


There is probably a way to do it via sockets. I played around
but couldn't figure out how to decode the gzipped data properly,
gzuncompress() gave me a data error. I found this suggestion
<http://bugs.php.net/bug.php?id=2805 1&edit=1> which might help
you out.

hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Jul 17 '05 #4
Thanks for your help,
I sorted it out, putting bits & pieces together;
all hail to the internet!
....It helps us to solve trouble we wouldn't have without it %&$§!!!
<?php

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

// see: de.php.net/manual/en/function.gzenco de.php
// there might be better versions
function gzdecode($strin g){
$string = substr($string, 10);
return gzinflate($stri ng);
}

function get_gzipped_dat a($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_dat a($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

bn*****@g214mx. net
(remove numbers to despam)
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2275
by: Phil Powell | last post by:
// PROCESS XML CONTENT INTO DYNAMICALLY-NAMED ARRAYS foreach (array('mime', 'state', 'country') as $val) { $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, ${$val . 'XML'}, ${$val . 'XMLArray'}, $tags); xml_parser_free($parser); $myXMLArray = ${$val . 'XMLArray'}; for ($i = 1; $i < @sizeof($myXMLArray) - 1; $i++) { if ($myXMLArray) {
7
2384
by: Michael J. Astrauskas | last post by:
I have a script, which I've called test-loadpic.php and some pages reference it by means of <img src="test-loadpic.php?sourcepic=$picNum"> where $picNum stores a number. This part itself works fine. test-loadpic.php uses the "sourcepic" GET variable to reference a file on disk, get it's file/MIME type, transmit the headers and then the raw image. The important code is below:
3
3653
by: Oxygenearth | last post by:
Please who could help me with this... I had my structure in Win32, with Apache, PHP, and MySQL, I had a page in which I am transfering an image to the database in MySQL using PHP. But now I am in Apache/Linux/MySQL(FreeBSD) with the same files. My problem is.. when I try to submit the variables to the php file, this does not get the binFile, in other words, the file($_POST) does not pass throug the SUBMIT html statemenT, so it is not...
2
2465
by: Sean Dotson | last post by:
I have a form that passes variables to an asp file and then uploads a file. For some reason the request.form is not getting the info from the form. It's returning blanks. Any insight would be appreciated.... Here is the asp file <HTML> <HEAD> <TITLE>File Upload Results</TITLE>
22
2804
by: stoppal | last post by:
need to extract all text between the following strings, but not include the strings. "<!-- #BeginEditable "Title name" -->" "<p align="center">#### </p>" I am using preg_match(????, $s, $results)
0
1729
grassh0pp3r
by: grassh0pp3r | last post by:
Hello, I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but I want the latest comment to be on top, and that's where I'm running into trouble. Since I know very little about PHP, I thought I was clever in what I came up with. I think it can work if I get the coding right. Let me know if my logic is wrong. I'm...
1
6971
by: Paul Smith | last post by:
Hi, I'd like to read a series of sqlite database files that have already been gzipped and was wondering if this can be done on the fly. In other words, can I avoid explicitly unzipping the file into another file, but instead get an SQL connection to the zip file either directly (can't see an option to do this) or to an object in memory resulting from unzipping, eg. (hypothetically); import gzip from sqlite3 import dbapi2 as sqlite
3
1593
by: 2good2b | last post by:
Hi, How can I differentiate between regular content and gzipped content on websites? Are there any other kinds of contents I should refer to? (I'm talking about websites-not applications) I would appreciate any ref. Thanks,
5
2960
by: DR | last post by:
Why is its substantialy slower to load 50GB of gzipped file (20GB gzipped file) then loading 50GB unzipped data? im using System.IO.Compression.GZipStream and its not maxing out the cpu while loading the gzip data! Im using the default buffer of the stream that i open on the 20GB gzipped file and pass it into the GZipStream ctor. then System.IO.Compression.GZipStream takes an hour! when just loading 50GB file of data takes a few minutes!
0
11123
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11299
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8219
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6308
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4910
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.