PDA

View Full Version : [PHP] Page Loading Time



Buax
04-03-2008, 10:35 PM
I would of posted in the correct section but I can't therefore, logically, I thought I should post here. Sorry if I was incorrect in doing this, if a moderator could please move my topic.

I noticed how a lot of websites have stat scripts with hit-counters and such, here is something you can add to them. A page loading time script! This will display how long it took them to load the web page they are on.

First off, you will need to place this right at the top of the page.


<?PHP
$m_time = explode(" ",microtime()); $m_time = $m_time[0] + $m_time[1];
$starttime = $m_time;
?>

This will start a timing script to time how long it too load the web page.

Now this is here it calculates how long it took to load the page, this needs to be as far down as possible on you're page.

<?
$round = 3; // Script by Buax from Habbox Forum
$m_time = explode(" ",microtime());
$m_time = $m_time[0] + $m_time[1];
$endtime = $m_time;
$totaltime = ($endtime - $starttime);
echo "Page loading took:". round($totaltime,$round) ." seconds to load.";
?>

Forge
04-03-2008, 10:39 PM
It goes under tutorials pal ;)

Thanks alot though. +Rep even though it means nothing anymore lol

--ss--
04-03-2008, 10:39 PM
Hey,

Nice tutorial and will come in handy, You could of added some more comments to show what everything means though ;).

You're right , only mods can move it to the tutorial section , I'll move soon if you get enough good feedback ;).

Buax
04-03-2008, 10:45 PM
It goes under tutorials pal ;)

Thanks alot though. +Rep even though it means nothing anymore lol
Only moderators can move it sadly. :(

Thanks for the rep! It doesn't matter. It's the thought that counts. :)


Hey,

Nice tutorial and will come in handy, You could of added some more comments to show what everything means though ;).

You're right , only mods can move it to the tutorial section , I'll move soon if you get enough good feedback ;).
I will do from now on! Didn't think about that. Cheers.

Ok. Hopefully it'll be worth moving. :)

LegendOfNoob
04-03-2008, 11:16 PM
Nice Buax
*Vote to Tutorials*
this could be quite a help to everyone

Also:
i was wondering why the tutorials section was so old silly hxf needs to let users post tuts :)

Colin-Roberts
04-03-2008, 11:25 PM
Page loading took:1204672157.39 seconds to load. Messed Up
Page loaded in 0.59 Seconds
is that a bad load time?

Buax
04-03-2008, 11:28 PM
Page loading took:1204672157.39 seconds to load. Messed Up
How many lines is you're page you tested it on? It bases it the web-browser reading though the script which is why you need to place the end-timer at the end when it's read though the file etc.

Don't really know how to fix it for you, worked fine in all of my tests so. Sorry I guess. If you could test it on a small-page, just like 10-50 lines of script or whatever I'd be thankful. :)

Colin-Roberts
04-03-2008, 11:34 PM
Theres no way it took 20 077 869 minutes to load my page. Your script has a part wrong with it.

<?php $load = microtime();
print (number_format($load,2));
?>

Short & Sweet

Agnostic Bear
05-03-2008, 03:24 PM
function do_microtime( $microtime )
{
if( list( $ms, $s ) = explode( " ", $microtime ) )
{
return( (float)$ms + (float)$s );
}
else
{
return $microtime;
}
}


i use that then just do $time = do_microtime( microtime() );

Want to hide these adverts? Register an account for free!