<?xml version="1.0" encoding="utf-8"?>
<tutorial>

<description>Learn how to output the time a page takes to load.</description>
<keywords>tutorial, PHP, tutorials, page, loading time, micro, micro(), page load</keywords>
<title>Page Loading Time</title>

<slug>
Learn how to output the time a page takes to load.
</slug>

<text>
Have you ever noticed that lots of websites feature a little "Page loading took x.xxx seconds to load" at the bottom of their pages?
It's a pretty simple thing to make and gives your site something that we all love... Stats!
<br></br><br></br>
Here is what we have to do:
<ol>
	<li>Get the time in micro-seconds using the function: <link><url>http://www.php.net/manual/en/function.microtime.php</url>microtime()</link>.</li>
	<li>Turn the micro-time into an array using the <link><url>http://www.php.net/manual/en/function.explode.php</url>explode()</link> function.</li>
	<li>Add the two parts to the array together (the micro-seconds to the seconds).</li>
	<li>Repeat steps 1,2 and 3 for the bottom of the page</li>
	<li>Find the total loading time by taking the time taken at the end of the page from the time taken at the top of the page</li>
	<li>Round the microtime and return it to the browser</li>
</ol>
Here is the code:
<br></br><br></br>
Put at the <b>top</b> of your page:

<![CDATA[
<pre>
&lt;?
 $m_time = explode(" ",microtime()); 
 $m_time = $m_time[0] + $m_time[1]; 
 $starttime = $m_time;
?&gt;
</pre>
]]>

Put at the <b>bottom</b> of your page.

<![CDATA[
<pre>
&lt;?
 $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 "Page loading took:". round($totaltime,$round) ." seconds"; 
?&gt;
</pre>
]]>
That's it. If you have any questions, feel free to post about it and we'll try to help out.
</text>

</tutorial>
