473,387 Members | 1,347 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,387 software developers and data experts.

Requesting Compressed Pages?

I have a script for requesting HTTP resources and I want it to use HTTP
compression (to reduce bandwidth), if possible. What's the best way to
do this? I've tried using zlib functions but they always return FALSE.
And I've tried to use the zlib wrapper, which works but makes
non-compressed resources take longer.

TIA.

Jul 17 '05 #1
8 2305
Hello,

On 12/21/2003 11:03 AM, Keith Bowes wrote:
I have a script for requesting HTTP resources and I want it to use HTTP
compression (to reduce bandwidth), if possible. What's the best way to
do this? I've tried using zlib functions but they always return FALSE.
And I've tried to use the zlib wrapper, which works but makes
non-compressed resources take longer.


Do you want to serve compressed pages via PHP or request compressed
pages to be retrieved from a remote server?

--

Regards,
Manuel Lemos

Free ready to use OOP components written in PHP
http://www.phpclasses.org/

Jul 17 '05 #2
Manuel Lemos wrote:

Do you want to serve compressed pages via PHP or request compressed
pages to be retrieved from a remote server?


Request compressed pages. I can find all sorts of documentation and
code examples for the former, but not any about requesting pages. To be
more accurate, I don't know how to decompress the pages. I can request
them with no problem, but the information isn't of use to me in
compressed form.

Jul 17 '05 #3
Keith Bowes <do****@spam.me> wrote:
Request compressed pages. I can find all sorts of documentation and
code examples for the former, but not any about requesting pages. To be
more accurate, I don't know how to decompress the pages. I can request
them with no problem, but the information isn't of use to me in
compressed form.


How do you request the page? HTTP/1.0 or HTTP/1.1? In the later case you
might get a chunked response (tranfser-encoding). See 3.6.1 Chunked
Transfer Coding of rfc 2616.

--

Daniel Tryba

Jul 17 '05 #4
Daniel Tryba wrote:

How do you request the page? HTTP/1.0 or HTTP/1.1? In the later case you
might get a chunked response (tranfser-encoding). See 3.6.1 Chunked
Transfer Coding of rfc 2616.


Yeah, I use HTTP/1.1. I've read the HTTP/1.1 spec, but Chunked Encoding
didn't make sense. I'll try to read it again.

Jul 17 '05 #5
Ok, I might be missing something so please forgive me.

If you are able to have succcess with the zlib library, then you 90%
done, you just need to look at the return header from the server.

your request should look like this (edit as needed)

$hHOST = "www.somedomain.com"; // the domain name for the page
$hURI = "/page_to_get.html"; // the page you want
$hREF = "http://mysite.com/was"; // in case you need the referer
$hAGENT = "My fuzzy web bot v1.0"; // the name of the user agent
(browser), IE or Netscape, etc..
$header = "GET $hURI HTTP/1.1" .
. "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, "
. "application/vnd.ms-powerpoint, application/vnd.ms-excel,
application/msword, "
. .application/x-shockwave-flash, */*\n"
. "Host: $hHOST\n"
. "Referer: $hREF \n"
. "User-Agent: $hAGENT\n"
. "Accept-Encoding: gzip\n"
. "Accept-Language: en-us\n"
. "Connection: Close\n"
. "\n";

now send the $header string to the server after you connect to it,
then look for this line from the server

"Content-Encoding: gzip"

if you find gzip in the encoding header that the server sends back,
then it is sending back encoded data, otherwise it did not encode it.

I hope this help.

Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #6
CountScubula <sc*****@hotmail.com> wrote:
Ok, I might be missing something so please forgive me. [snip] now send the $header string to the server after you connect to it,
then look for this line from the server

"Content-Encoding: gzip"

if you find gzip in the encoding header that the server sends back,
then it is sending back encoded data, otherwise it did not encode it.


You are missing something indeed. The OP doesn't have problems
requesting compressed files, but _decompressing_ them.

Now if he only posted some sample code with a url to test, we might be
able to help him point to the flaws in his script....

--

Daniel Tryba

Jul 17 '05 #7
Daniel Tryba <ne****************@canopus.nl> wrote in message news:<bs**********@news.tue.nl>...
CountScubula <sc*****@hotmail.com> wrote:
Ok, I might be missing something so please forgive me.

[snip]
now send the $header string to the server after you connect to it,
then look for this line from the server

"Content-Encoding: gzip"

if you find gzip in the encoding header that the server sends back,
then it is sending back encoded data, otherwise it did not encode it.


You are missing something indeed. The OP doesn't have problems
requesting compressed files, but _decompressing_ them.

Now if he only posted some sample code with a url to test, we might be
able to help him point to the flaws in his script....

Sounds good to me, :)
I have a small web page that reqest data from server:
http://gzen.myhq.info/serverchk.php

they should try using that link to see if my script can do it?
..... just a thought
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #8
BTW,

With chunked,

after the header (+ 1 blank line)
you will recieve a number, that number is how many bytes follow
read that many bytes in your buffer, that is the chunk.

then you will recieve another number, that is the next chunk size,
read that many bytes, then repeat

when you recieve 0 as the number, you are done.
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #9

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

Similar topics

8
by: Dennis Hotson | last post by:
Hi, I'm trying to write a function that adds a file-like-object to a compressed tarfile... eg ".tar.gz" or ".tar.bz2" I've had a look at the tarfile module but the append mode doesn't support...
1
by: Ron Clarke | last post by:
Does anyone know how to get the compressed size of a file on disk? FileInfo.Length gives the uncompressed size of a file, but I need to find the amount of disk space taken up by files in compressed...
5
by: PerryG | last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using HttpWebRequest to an Apache server. The Apache server is using a the 'mod_deflate' server to decompress the incoming...
4
by: Pavel | last post by:
Hello. I am trying to make a folder compressed and failing miserably. Below are three ways that I tried to make it compressed, all of them compile and run w/o any problems, but the folder is...
1
by: Charles A. Lackman | last post by:
Hello, I have made an aspx web application that is using Forms Authentication. Each unsecure page has a custom user control on it that will allow the visitor to login and enter secure pages. The...
1
by: Prabhu | last post by:
Hi. We have an ASP.net Web application in which some of the pages are to be served over secure channel using HTTPS. We have built a framework that allows pages to be served over secure channel...
8
by: robert | last post by:
Hello, I want to put (incrementally) changed/new files from a big file tree "directly,compressed and password-only-encrypted" to a remote backup server incrementally via FTP,SFTP or DAV.... At...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.