473,372 Members | 804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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_contents("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 2585
"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_contents("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(gzcompress($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@fung.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(gzcompress($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_contents 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_contents("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(gzcompress($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@fung.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_contents 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=28051&edit=1> which might help
you out.

hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.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.gzencode.php
// there might be better versions
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

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
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);...
7
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...
3
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...
2
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...
22
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,...
0
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...
1
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...
3
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...
5
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.