Jump to content
MakeWebGames

Using CURL to record website response times (HTTP vs HTTPS)


Isomerizer

Recommended Posts

I am trying to develop a basic PHP tool to record the response times of a website, when using HTTP and HTTPS.

Overall, I wish to record several times and then compare them. To give an overview of the difference of speed between HTTP & HTTPS.

I am using CURL, I have made this so far:

 

<?php

// curl handle
$ch = curl_init($_GET['x']); // ?x= url target

curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); // fresh connection, don't cache
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 
curl_setopt($ch, CURLOPT_CERTINFO, 1); // enables SSL ?

// execute / load website
curl_exec($ch);

// check for error
if(!curl_errno($ch))
{
$c = curl_getinfo($ch);

echo 'Sending request to: ' . $c['url'].' <br />
        Connect time: '.$c['connect_time'].'<br />
            Name Lookup time: '.$c['namelookup_time'].'<br />
                Pre transfer time: '.$c['pretransfer_time'].'<br />
                    Header size: '.$c['header_size'].'<br />
                        Average download speed: '.$c['speed_download'].'<br />
                            Took <b>'.$c['total_time'].'</b> seconds in total';
}

// close curl
curl_close($ch);

?>

 

Does anyone know if CURL does indeed take into account the HTTPS headers and additional procedures it completes (e.g. handshake phase) when establishing a connection?

I think I have set the CURL options correctly, I have ran several tests, they seem to differ. But I need to know if CURL is accurate for this sort of testing, or would you recommend something else?

HTTP: http://www.isomerizer.com/curl.php?x=http://www.google.com

HTTPS: http://www.isomerizer.com/curl.php?x=https://www.google.com

Also, would my webserver hosting the PHP make a difference?

Link to comment
Share on other sites

I don't fully remember how HTTPS is implemented, so I can't really answer you with full details, but as far as I remember SSL with public and private key, the first exchange is made using those keys:

Client sends a bidirectional random key to communicate afterward to the server, encrypted with the public key of the server. Further communication between the 2 is made via the symmetrical key, because it's faster.

So if HTTPS is the same (and if I remember right it is), that should mean that the first HTTPS call you do should be slower and then faster. Therefore what do you want to test? The first communication or communication in general? Also I don't know how CURL is implemented, don't know if it cache something, and how the implementation is done. Too many unknown pieces on my side.

Finally as any benchmark, you will see many different timing, depending on your HTTP & HTTPS server as well as your client testing. So if you want to have a clean setup just to test the HTTP & HTTPS speed difference, build 2 computers on a network without anything else attached. And run your test many many times, to average the data.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...