Finding the size of a generated page and the time it takes?

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
toms100
Forum Contributor
Posts: 119
Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK

Finding the size of a generated page and the time it takes?

Post by toms100 »

is it possible using a php function to display the size of the generated page and how long it took to generate?
any help is appreciated

Tom
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

filesize(string filename) will give you the size of the file. Generation time I am not so sure on.
toms100
Forum Contributor
Posts: 119
Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK

Post by toms100 »

how do i make $filesize show the size of the page that has been generated? if say the page generated is bob.php?dave=no can i use filesize(bob.php?dave=no ) or would filesize($PHP_SELF) work?
thanks for reply

Tom
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

take a look at http://www.php.net/manual/en/reserved.variables.php
I'd suggest $_SERVER['SCRIPT_FILENAME'] or $_SERVER['PATH_TRANSLATED']
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

You can time a script with:

Code: Select all

function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}

$start = getmicrotime();

... the script to be timed ...

$end = getmicrotime();
$time = $end - $start;
echo "<p>time=" . $time . "</p>";
To get the size of a browser page you have built with php a quick hack would be to use the view source command in the browser, save the file and then check out the size.

You could also do that in php by outputting the page to a file and using php to check the size.

Filesize(string filename) would only work if php doesn't add anything to an included/eval'd file used to build a page. However, pages built entirely with php - or with some php and some html included from a template - don't have a fixed file corresponding to the browser output to filesize() on.

Note that output-ing pages to a file can also be used to cache dynamic pages which don't change too often: they'll load quicker from pure html than if they are dynamically generated by php each time.
Last edited by McGruff on Thu Aug 11, 2005 1:55 pm, edited 1 time in total.
toms100
Forum Contributor
Posts: 119
Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK

Post by toms100 »

thanks mc Gruff you seem to be pretty good at this php lark:) i think ill try to save the output to a file and check that size, and the time feature works nicely:)
usefull reply to volka

Tom
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I've only been working with php for a few months but it's an easy language to pick up - and there are lots of free resources to help, such as this board. I'm really amazed at what a great community there is around open source.

Good? Nah - actually I always tell people the wrong answers: don't want any competition in the jobs market :D
toms100
Forum Contributor
Posts: 119
Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK

Post by toms100 »

yeah there seems to be alot more people willing to help than there is with asp. ive done asp for a year or two (never achieved much or got perticually good, just made the odd forum and stuff) i found asp easy to do database stuff but there was very little support and i really wanted to get away from microsoft
Post Reply