PHP measuring page load time

PHP, Programing Add comments

In this tutorial you will learn from a simple code how to generate the page loading time using pure PHP programing.
The idea is simple, this script generates a number that counts in seconds the page loading time.

It’s a very simple script and is accurate to 0.000000000000001 seconds.

Firstly place the following code at the very top of your page:

PHP:
  1. <?php
  2. $time = microtime();
  3. $time = explode(' ', $time);
  4. $time = $time[1] + $time[0];
  5. $begintime = $time;
  6. ?>

Next add the following code at the very bottom of the page. You can change the last line to whatever you would like your viewers to see.

PHP:
  1. <?php
  2. $time = microtime();
  3. $time = explode(" ", $time);
  4. $time = $time[1] + $time[0];
  5. $endtime = $time;
  6. $totaltime = ($endtime - $begintime);
  7. echo 'PHP parsed this page in ' .$totaltime. ' seconds.';
  8. ?>

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in