tags:

views:

30

answers:

2

I'm using PHP Curl to measure download times for a webpage. I know this isn't a good representation of actual download times for a browser; but I'm trying to get as close as possible using this method.

My webpage has 3 files associated with it

  1. index.html
  2. my_pic.gif
  3. style.css

I'm doing a Curl on each of those files then adding the download times together to get the total download time.

My question is how should I do the calculations to get as close as possible to simulating a browser download?

The Curl options for measuring download times are:

CURLINFO_TOTAL_TIME
CURLINFO_NAMELOOKUP_TIME
CURLINFO_CONNECT_TIME
CURLINFO_PRETRANSFER_TIME
CURLINFO_STARTTRANSFER_TIME

Would a browser go through all of those steps for each of the 3 files above?

For Example:

Let's say I do a CURLINFO_TOTAL_TIME on index.html.

Should I also do a CURLINFO_TOTAL_TIME on my_pic.gif and style.css? Then add those numbers to the CURLINFO_TOTAL_TIME on index.html.

OR

Should I do a CURLINFO_TOTAL_TIME minus CURLINFO_STARTTRANSFER_TIME on my_pic.gif and style.css? Then add those numbers to the CURLINFO_TOTAL_TIME on index.html.

+3  A: 

Personally I would do this:

$t1 = microtime();
// do all the curl requests
$t2 = microtime() - $t1;
echo $t2;
sberry2A
Wouldn't that be the same as doing a CURLINFO_TOTAL_TIME on all 3 files then adding them together?
Mark
Yes, except `CURLINFO_TOTAL_TIME` returns seconds, not microseconds.
sberry2A
A: 

Getting the exact result will be difficult, because every browser handles it slightly differently.

Name lookup is only done once per domain, so if my_pic.gif and style.css reside on the same domain lookup already happened for index.html.
Secondly, most browsers will request multiple files at once, so my_pic.gif and style.cs would be requested at the same time and only the longer download would count. Of course with bigger files on would need to account for user cable speed, but that should not be the problem here.

A good estimation should be: TOTAL_TIME(index.html) + max( TOTAL_TIME(my_pic.gif) - NAMELOOKUP_TIME(my_pic.gif), TOTAL_TIME(style.css) - NAMELOOKUP_TIME(style.css) )

If you want to test how long you really need for that download, you can get the firefox extension YSLOW. It will tell you how long the whole page took to download and draw a nice graph of which element was downloaded when and how long it took.

Darcara
-1: from RFC-2616 "A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy". But really the only practical way to measure page response (as opposed to URL response) is on the brwoser using javascript.
symcbean
I voted this one up and selected it as the correct answer because it actually answers the question I asked. I understand the method I'm using to determine download time is not ideal; however my original question was how to get as close to browser download time as possible with the method I'm using. I was not really interested in another way to calculate download time.
Mark