Linux: 使用Curl命令查看 http 请求各阶段响应时间

~$ curl -o /dev/null -s -w %{time_namelookup}:%{time_connect}:%{time_starttransfer}:%{time_total} "https://service.5gcds.com:8890/isure6.stream.qqmusic.qq.com/C400000DNBpp3nTPMM.m4a?guid=2000000162&vkey=16CA4105AA83FD348BD7D4986E3A3AB66FDB3B666A81693442849AF3F320EACC04EEEB4D40702C8F79318455A21BA331B1CB08161BA4996B&uin=&fromtag=262"
0.185274:0.264978:5.796605:23.723368 (走cdn)

~$ curl -o /dev/null -s -w %{time_namelookup}:%{time_connect}:%{time_starttransfer}:%{time_total} "https://isure6.stream.qqmusic.qq.com/C400000DNBpp3nTPMM.m4a?guid=2000000162&vkey=16CA4105AA83FD348BD7D4986E3A3AB66FDB3B666A81693442849AF3F320EACC04EEEB4D40702C8F79318455A21BA331B1CB08161BA4996B&uin=&fromtag=262"
0.205355:0.302128:0.771375:3.684324 (不走cdn)

下面解释来自https://blog.csdn.net/wuhendadi/article/details/100101289

示例:

curl -o /dev/null -s -w "time_namelookup:%{time_namelookup} time_connect: %{time_connect} time_starttransfer: %{time_starttransfer} time_total: %{time_total} " "https://www.baidu.com/"

输出:

time_namelookup: 0.005252

time_connect: 0.014415

time_starttransfer: 0.051369

time_total: 0.051625

上面这条命令及返回结果可以这么理解:

time_namelookup: DNS 服务器域名解析的时间(以上时间单位都是s) 。

time_connect: client 发出请求,到 c/s 建立TCP 的时间;里面包括 DNS 解析的时间 。

time_starttransfer: client 发出请求;到 server 响应发出第一个字节开始的时间;包括前面的2个时间 。

time_total: 从请求发起到链接关闭的总耗时。

curl 命令参数解释:

-o: 把curl 返回的html、js 写到垃圾回收站[ /dev/null]
-s: 去掉所有状态
-w: 按照后面的格式写出rt
time_namelookup: DNS 解析时间,从请求开始到 DNS 解析完毕所用时间,单位为秒,如果测试的地址为IP,这里耗时即为0
time_commect: client 和 server 端建立 TCP 连接的时间,连接时间,从开始到建立TCP连接完成所用时间,包括前边DNS解析时间,如果需要单纯的得到连接时间,用这个 time_connect 时间减去前边 time_namelookup 时间
time_starttransfer: 从 client 发出请求;到 web server 响应第一个字节的时间
time_total: client 发出请求;到 web server 发送回所有的相应数据的时间
http_code: http状态码,如200成功,301重定向,404资源未找到,500服务器错误等
————————————————
版权声明:本文为CSDN博主「古战」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wuhendadi/article/details/100101289

原文地址:https://www.cnblogs.com/tonyxiao/p/15385289.html