Page Timerz

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
Chillwabbitt
Forum Newbie
Posts: 8
Joined: Fri May 24, 2002 3:04 am

Page Timerz

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.";
?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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:
Chillwabbitt
Forum Newbie
Posts: 8
Joined: Fri May 24, 2002 3:04 am

Page Timerz

Post by Chillwabbitt »

Tang Ya Belly Much :D
Post Reply