Full code - pageload.php

$startTime = array_sum(explode(' ', microtime()));
//code
$endTime = array_sum(explode(' ', microtime()));
echo 'This page took approximately '.round($endTime - $startTime, 7).'seconds to load.';

Download the code »

Tutorial

This code calculates the time it takes to interpret and run the PHP code.

$startTime = array_sum(explode(' ', microtime()));

The time that the code starts is recorded. This is done by calling microtime which returns 2 parts (the current time in seconds and milliseconds), for better accuracy we sum both parts.

//code

Insert the script here that will be timed.

$endTime = array_sum(explode(' ', microtime()));
echo 'This page took approximately '.round($endTime - $startTime, 7).'seconds to load.';

Finally the time after the code has been interpreted is stored and the difference between start time and end time is printed to the user.

Adobe Fireworks® Adobe Flash® and Adobe Photoshop® are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries.
MySQL is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Copyright Pixelcode 2005 - 2010