Web page size retrieval

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Web page size retrieval

Post by pickle »

Hi All,

Is there a quick and easy, or at least somewhat simple, way to get the total size of a web page, images and all? I'm working on a number of website front ends for the organization I work for, and I want to see how big each front end ends up being?

The only plans I had so far was to get the size of the html, retrieve it, parse it, then get the file size of every image tag. Is this how it has to be done? Thanks.

-Dylan
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: Web page size retrieval

Post by TheBentinel.com »

pickle wrote:Hi All,

Is there a quick and easy, or at least somewhat simple, way to get the total size of a web page, images and all? I'm working on a number of website front ends for the organization I work for, and I want to see how big each front end ends up being?
-Dylan
It sounds like you're looking for a programmatic way, and I think the long and drawn out method is your only choice on that one. Even the server that serves up the HTML doesn't know how big the overall page will be, since it may not host all the images and such.

But, if you don't mind doing a little manual work, you can save the page (in Internet Explorer) as a web archive (File-->Save As-->Save as Type = Web Archive (*.mht)) and then check the size of that file. It pops in some MIME overhead, but it would give you a good idea of the size of the overall page, images and all.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Web page size retrieval

Post by pickle »

TheBentinel.com wrote: But, if you don't mind doing a little manual work, you can save the page (in Internet Explorer) as a web archive (File-->Save As-->Save as Type = Web Archive (*.mht)) and then check the size of that file. It pops in some MIME overhead, but it would give you a good idea of the size of the overall page, images and all.
Sounds like a plan. Thanks.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Out of curiosity - if you do output buffering in the page, does it include the pictures in the size?

If so, thats a solution. If not, perhaps get the output buffer (ob_*) size, and then add the image sizes with a file system check.
aleigh
Forum Commoner
Posts: 26
Joined: Thu Mar 25, 2004 11:06 am
Location: Midwestern United States
Contact:

Re: Web page size retrieval

Post by aleigh »

pickle wrote:Hi All,

Is there a quick and easy, or at least somewhat simple, way to get the total size of a web page, images and all? I'm working on a number of website front ends for the organization I work for, and I want to see how big each front end ends up being?

The only plans I had so far was to get the size of the html, retrieve it, parse it, then get the file size of every image tag. Is this how it has to be done? Thanks.

-Dylan
Take a look at Snoopy, which is a handy implementation of a web client. The strategy you probably want to look at is to download the HTML, find the IMG tags, and then at least request them from the server and hope that it provides you Content-length in the response.

There is no guarantee that Content-length will be provided, in which case you have to download the entire image and see how big it turned out to be.
Post Reply