page load time

Posted on 2011-03-15
Medium Priority
Last Modified: 2012-05-11

I have an image gallery and I want to display the time it took all of the photos to load after they are done loading.
Question by:Computer Guy
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 35138082
Firefox + Yslow + firebug

Author Comment

by:Computer Guy
ID: 35138092
On the page to the user not browser
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35138665
Look at http://www.php.net/microtime

There are examples in the code of how to use that to time a script, but put one line at the start after the <?php tag and another near the end and simply subtract, then echo the result onto the screen.

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.


Expert Comment

ID: 35138671
You could probably start a javascript counter and output it to a field, but I'm not sure how you would stop this when the last image is loaded i.e. if the functionality is there in the browser to trigger an event when all images have been downloaded.
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35138683
From the page linked to above...

$time_start = microtime(true);

// Sleep for a while

$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Did nothing in $time seconds\n";

Open in new window

LVL 34

Accepted Solution

Beverley Portlock earned 2000 total points
ID: 35138717
Ahh.. just noticed, it's the photos you're timing, not the script. In that case it'll be javascript, not PHP. Sorry......

Author Comment

by:Computer Guy
ID: 35140431
Do you have a Javascript solution?
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35146602
"Do you have a Javascript solution?"

No. I'm reasnably good at javascript but PHP is my main area of expertise. Having said that it seems to me that the real problem is the customer's machine and the ADSL (or whatever) line used to view the website. The PHP script will simply add <img../> tags in a fraction of a second and it is the process of downloading them to the client machine that takes all the time, so where you say "On the page to the user not browser" you need to measure the whole page download.

Now there are three ways of doing things in Javascript at preset times

1. Put javascript in the <head> section. This will run BEFORE the page shows up to the user

2. Put javascript at the end of the <body> section. This runs as soon as the HTML is downloaded, but pictures etc may still be downloading

3. Put javascript in a function and trigger using the  onLoad event. This should not trigger until everything has loaded.

So, we can try something like this (UNTESTED)

      var startTime = new Date().getMilliseconds();
      var actualTime = 0;
      var endTime = 0;

      function timeLoad() {
            endTime = new Date.getMillseconds();
            actualTime = (endTime - startTime ) / 1000;
            alert( "It took " + actualTime + " seconds" );
<body onLoad='timeLoad()' >

As I said, javascript is not my strongest area so I may be a bit off with this

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question