Jump to content
xisto Community
Sign in to follow this  
cragllo

Page Loading Time how long does your page take to load?

Recommended Posts

All you have to do is add this code to your page where you want the loading time to be shown, the bottom is the most common place.

<?php[br]$loadbegintime = microtime();[/br]$loadbeginarray = explode(" ", $loadbegintime);[br]$loadbegintime = $loadbeginarray[1] + $loadbeginarray[0];[br][/br]$loadendtime = microtime();[/br]$loadendarray = explode(" ", $loadendtime);[br]$loadendtime = $loadendarray[1] + $loadendarray[0];[br][/br]$total_script_time = $loadendtime - $loadbegintime;[br][/br]echo "This Page took " .round($total_script_time , 6) ." seconds to load!";[/br]?>

Share this post


Link to post
Share on other sites

Ah great! I have been looking for this code for ages! I didn't understand a previous example i read. I will use this on my site ;-)

Share this post


Link to post
Share on other sites

Ive added the page loading time to my page but I'm sure its off somewhere, how can my page load in less than 1/10 of a second? It doesn't make sense unless the Xisto servers are extremely fast <_<

Share this post


Link to post
Share on other sites

It shows teh time it took the server to proccess the page and deliver it. Not the time it takes the user to download off of the server.

Thanks, that explains alot. I thought it was the time it took your browser to process the page :D

Share this post


Link to post
Share on other sites

Here is a better one using functions:

<?php/*** Simple function to replicate PHP 5 behaviour*/function microtime_float(){   list($usec, $sec) = explode(" ", microtime());   return ((float)$usec + (float)$sec);}$time_start = microtime_float();// Sleep for a whileusleep(100);$time_end = microtime_float();$time = $time_end - $time_start;echo "Did nothing in $time seconds\n";?>

This is quite self explanatory.
Also in PHP 5 onwards there is a better option:

<?php$time_start = microtime(true);// Sleep for a whileusleep(100);$time_end = microtime(true);$time = $time_end - $time_start;echo "Did nothing in $time seconds\n";?>

Hope you guys like it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.