Page 1 of 1

Page Timerz

Posted: Fri May 24, 2002 3:10 am
by Chillwabbitt
Hello me again

Please can you tell me how they execute this kind of timer on the page

"[i]phpBB Created this page in 0.220205 seconds : 15 queries executed : GZIP compression enabled[/i]"

If posible please leave an example (I fairly new at all of this)

Thanx a stack

Posted: Fri May 24, 2002 3:28 am
by Benjamin
I am thinking that you could use gmdate at the beginning and end of the script to do something like that.

For example this might work but I am just typing it out so if it don't work don't blame me:)

Code: Select all

//Put this at the top of the script
<?php
function calc($script_started_at, $script_ended_at,&$time_to_execute)
&#123;
$time_to_execute = ($script_ended_at - $script_started_at);
return $time_to_execute;
&#125;
$script_started_at = gmdate(U);
?>

//Put this at the bottom of the script
<?php
$script_ended_at = gmdate(U);
calc($script_started_at,$script_ended_at);
echo "This page created in " . $time_to_execute . "seconds.";
?>

Posted: Fri May 24, 2002 4:11 am
by Benjamin
Here ya go I found some code online that will do the trick...

Code: Select all

function getmicrotime()&#123; 
    list($usec, $sec) = explode(" ",microtime()); 
    return ((float)$usec + (float)$sec); 
    &#125; 

$time_start = getmicrotime();
    
for ($i=0; $i < 1000; $i++)&#123;
    //do nothing, 1000 times
    &#125;

$time_end = getmicrotime();
$time = $time_end - $time_start;

echo "Did nothing in $time seconds";

On my box this returned..
Did nothing in 0.0010370016098022 seconds
Anyone wanna race :wink:

Page Timerz

Posted: Mon May 27, 2002 3:03 am
by Chillwabbitt
Tang Ya Belly Much :D