开发者

Detailed URL fetch info in Ruby

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.

Detailed URL fetch info in Ruby

(source: pingdom.com开发者_高级运维)


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         
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜