views:

34

answers:

1

Is there any way I could get info such as how long did it take to connect to a remote server, time taken to receive the first byte of response, and the time taken to download the whole file?

I'm trying to create something like what Pingdom does.

alt text

+1  A: 

You can do it with sockets, like this:

require "socket"

# START MEASURING CONNECTION TIME
connection = TCPSocket.open("example.com", 80)
# END MEASURING CONNECTION TIME

connection.print "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"

# START MEASURING RESPONSE FETCHING TIME
response = connection.read
# END MEASURING RESPONSE FETCHING TIME

connection.close         
floatless