Page Loading Time
Learn how to output the time a page takes to load.
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!
Here is what we have to do:
- Get the time in micro-seconds using the function: microtime().
- Turn the micro-time into an array using the explode() function.
- Add the two parts to the array together (the micro-seconds to the seconds).
- Repeat steps 1,2 and 3 for the bottom of the page
- 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
- Round the microtime and return it to the browser