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
Finding the size of a generated page and the time it takes?
Moderator: General Moderators
take a look at http://www.php.net/manual/en/reserved.variables.php
I'd suggest $_SERVER['SCRIPT_FILENAME'] or $_SERVER['PATH_TRANSLATED']
I'd suggest $_SERVER['SCRIPT_FILENAME'] or $_SERVER['PATH_TRANSLATED']
You can time a script with:
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.
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>";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.
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
Good? Nah - actually I always tell people the wrong answers: don't want any competition in the jobs market
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