有什么方法可以获取信息,例如连接到远程服务器需要多长时间,接收第一个响应字节所花费的时间,以及下载整个文件所需的时间?
我正在尝试创建像Pingdom那样的内容。
alt text http://tools.pingdom.com/fpt/_img/img_explanation.gif
答案 0 :(得分:1)
您可以使用套接字执行此操作:
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