Hull Design Online

PHP Load Time

View demo

Page 1 | Page 2 | Page 3

This tutorial will demonstrate how to check how long your server is taking to generate content to the user's web browser. By running this on your website, you will be able to see which pages are taking longer than others to load - a must for any website developer!
In an unbelievably short amount of time, you will be running this script on any PHP enabled page in no time.

Let's get started then. Firstly, we need, as ever, to declare the start and opening of a PHP command. You need to do this at the very top of your page. You'll probably know how to do this, but just for the ease of copy and paste - this is the start of the script:

<?php

Now we've established that, let's move on. This script consists of using the microtime function. By using this, the script will return the current UNIX timestamp in microseconds. We use microseconds as you page should be generated in under one second. We then set $start to contain this.

<?php
$start = microtime();

If you've ever used microtime(); before, you'll know it consists of a space. We're going to remove that by using the explode(); function. All we're doing is telling the script to look for a space and assign the separate variables for each set. For example, the first value becomes $startarray[0] and the second becomes $startarray[1]. This completes the section of the code which needs to be at the top, so we can end the PHP tag too.

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

Move onto page 2 for the second part, which needs to be placed at the bottom of your page.

Page 1 | Page 2 | Page 3

Due to this page rendering fast, I've had to include the clients page in a hidden container. If you see any requests for images, don't panic. It's so that I can show an efficient example of the script working.
0 seconds

This tutorial is up to date as of 24 August 09. While you're here, why not check out more tutorials? You could also subscribe to our RSS Feed, or even check out our Twitter - follow us for the latest updates. For video tutorials, subscribe to our YouTube channel. Feel free to check out our blog for more updates.

 

 

Hull Design Online YouTube Channel Hull Design Online RSS

Bookmark and Share

Latest

Smoke Scene Design
Modern Bokeh Effect Realistic Snow Photoshop Layout
Create Newspaper Headlines Halloween Poster - Part 2 of 2 Halloween Poster - Part 1 of 2
Halloween Text Time Greeting Sticky Tape
Business Card Design Draw Lined Paper Amazing 3D Text
Stunning Typography Create Realistic Reflections Widescreen Border
Indented Text Effect Advanced Shadows Text Styling Tutorial
Website Status Checker Load Time Optimise Pages
Shorthand CSS Optimise Your Windows System Manage Your Passwords Safely and Securely