开发者

Detailed URL fetch info in Ruby

开发者 https://www.devze.com 2023-01-10 19:43 出处:网络
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?

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

精彩评论

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