Page generated time

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
swarfega
Forum Members
Forum Members
Posts: 174
Joined: Mon Sep 06, 2010 10:51 am

Page generated time

Post by swarfega »

Hi all. I would like to show the time a page is generated in. You get these at the bottom of some websites saying something like "Page generated in blah seconds".
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: Page generated time

Post by spcherub »

This is built into the configuration and you can turn it on by setting the show_performance_info variable in config.php to "true" (or anything else). This will print the performance information within HTML comments after the closing tag, so by default it is only visible upon doing a View->Source on the page.

If you want to actually display these numbers on the page, you will need to write a UDT that essentially does exactly what the code at the end of index.php does, namely:

Code: Select all

echo "This page was generated in ".microtime_diff($starttime,$endtime)." microseconds\n";
NOTE: I have not tested the above code, but the intent is correct. You will need to make sure that $starttime and $endtime value set in index.php are available globally or otherwise.

Hope that helps.
Sanjay
swarfega
Forum Members
Forum Members
Posts: 174
Joined: Mon Sep 06, 2010 10:51 am

Re: Page generated time

Post by swarfega »

Thanks for your reply. For some reason its not showing.

In global settings Ive put:

Code: Select all

<? $m_time = explode(" ",microtime()); 
$m_time = $m_time[0] + $m_time[1]; 
$starttime = $m_time; 
?>
In a footer block Ive put:

Code: Select all

<? 
$round = 3;// The number of decimal places to round the micro time to. 
$m_time = explode(" ",microtime()); 
$m_time = $m_time[0] + $m_time[1]; 
$endtime = $m_time; 
$totaltime = ($endtime - $starttime); 
echo "This page was generated in ". microtime_diff($totaltime,$round) ." microseconds"; 
?>
Post Reply

Return to “The Lounge”