Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

Displaying Load Times


When developing PHP-driven websites its often very useful to know how long your pages took to process.  This not only gives you some idea of the efficiency of your websites and of the server running them, but may help you diagnose problems, benchmark code corrections/additions, etc.  The best way to do this is program PHP to read the system time at the beginning of the page, scan it again near the end, and then work out the difference between the values.  To get us started, just add the following basic code near the top of your page, before all the main content:

<?php
$starttime = microtime();
$startarray = explode(" ", $starttime);
$starttime = $startarray[1] + $startarray[0];
?>

It may look complex, but the above code is actually dead simple.  Microtime is a function that returns a value giving the current time in seconds and milliseconds from the UNIX Epoch (internationally set as 0:00:00 January 1, 1970 GMT).   Explode then splits this value into its two component parts (seconds and milliseconds), and then inserts both values separately into an array.   With those values determined, of course, we can go on to insert the following code near the end of the webpage, after all the main code:

<?php
$endtime = microtime();
$endarray = explode(" ", $endtime);
$endtime = $endarray[1] + $endarray[0];
$totaltime = $endtime - $starttime;
$totaltime = round($totaltime,5);
echo "This page loaded in $totaltime seconds.";
?>

I'm pretty sure you can guess what's going on here.  The microtime is determined again and inserted into the endtime array.  We then delete the starttime array from it and come up with a brand new value, totaltime (which is the value we've wanted all along).  The number is then rounded to 5 significant figures, and output by the ECHO command.  If you've entered everything correctly, you should end up with a line of text saying something like this:

Page generated in 0.27283 seconds

And that, as they say, is that!   As you can probably guess, the lower this value the better the performance. Don't get too obsessed with these figures, though, because they also rely heavily on server load levels, mySQL commands, etc.  Just look at everything with a scientifically objective eye, and all will be fine... :)

- Tutorial written by Man1c M0g

Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments


There are no comments for this tutorial yet.
You can place a comment by clicking here.
Amazing Font Pack!

Featured Tutorialsmore

Artistic Color Iso...
Artistic Color Iso...
- Adobe Photoshop -
StarBurst Effects
StarBurst Effects
- Adobe Photoshop -
Thick Diagonal Lines
Thick Diagonal Lines
- Adobe Photoshop -
Painting A Wooden ...
Painting A Wooden ...
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Printer Friendly Version
Forum Threads

 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 11:16am
Activity: 1 replies, 867 views
 changes....
Author: supertackyman
Posted: Sep 12th, 2:56am
Activity: 2 replies, 1037 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 3:50pm
Activity: 0 replies, 1042 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 12:58pm
Activity: 0 replies, 1919 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 2:18pm
Activity: 0 replies, 1816 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 2:33pm
Activity: 0 replies, 14417 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 3:37am
Activity: 0 replies, 2712 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 2:19pm
Activity: 2 replies, 2752 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3427 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2344 views
 BioRUST Forums - Reply to Topic
Author: inonShozy
Posted: Jan 11th, 11:32am
Activity: 8 replies, 2482 views
 Version 2 of my portfolio site.
Author: andrewnleon
Posted: Jan 08th, 6:18am
Activity: 6 replies, 2792 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673