views:

27

answers:

3

Is there a way to determine how long it takes a web page, and all it's content, to load with PHP?

I have already tried this:

$time_start = microtime(true);

(All the content of the web page here)

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

However, the problem with this (as far as I can tell) is that I'm only calculating the time it takes the php script to execute. This doesn't factor in any images or videos that are on the page.

Is there a way to determine how long it takes a web page to load including images or videos using php?

Basically what I'm trying to do is test the speed of my server with out factoring in my connection speed.

+1  A: 

You might consider ab (ApacheBench). It's for testing the performance of your web server, but you can run it against a particular URL if you're just concerned about one page. One advantage is that it can run from the command line and issue multiple requests in parallel, enabling you to do some kind of load testing.

If you want to factor in how long it takes to actually load on the browser, you'll need some kind of javascript solution. One approach with code is presented in the article, Optimizing Page Load Time, which is worth reading.

ars
AB only tests PHP also - but it's more useful that microtime() for real-world stress tests.
Xeoncross
+1  A: 

You need to download firebug and then open the "net" tab and wait for the page to finish loading and it will show you the total load time of all requests.

Xeoncross
+1  A: 

Google Chrome has an amazing Audit tool built in which gives a good list of ways to improve a given site as far as speed goes. alt text

Farid