cURL 显示所有时间 DNS解析 TCP连接 总时间
1、curl -w参数
curl -h |grep "write-out"
-w, --write-out <format> Use output FORMAT after completion
2、显示所有时间示例
curl -o /dev/null -s -w "time_namelookup:%{time_namelookup}\ntime_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "https://const.net.cn/"
输出:
time_namelookup:0.058759
time_connect: 0.069912
time_starttransfer: 0.147355
time_total: 0.167685
3、参数说明
time_namelookup: DNS 服务器域名解析的时间(以上时间单位都是s)
time_connect: client 发出请求,到 c/s 建立TCP 的时间;里面包括 DNS 解析的时间
time_starttransfer: client 发出请求;到 server 响应发出第一个字节开始的时间;包括前面的2个时间
time_total: 从请求发起到链接关闭的总耗时
4、官方英文说明
time_appconnect: The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed. (Added in 7.19.0)
time_connect: The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
time_namelookup: The time, in seconds, it took from the start until the name resolving was completed.
time_pretransfer: The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
time_redirect: The time, in seconds, it took for all redirection steps including name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections. (Added in 7.12.3)
time_starttransfer: The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.
time_total: The total time, in seconds, that the full operation lasted.
5、格式可以使用字符串,格式化文件以及标准输入
The format can be specified as a literal "string", or you can have curl read the format from a file with "@filename" and to tell curl to read the format from stdin you write "@-".
6、使用格式文件示例
cat curl-format.txt
time_namelookup:%{time_namelookup}\n
time_connect:%{time_connect}\n
time_appconnect:%{time_appconnect}\n
time_redirect:%{time_redirect}\n
time_pretransfer:%{time_pretransfer}\n
time_starttransfer:%{time_starttransfer}\n
------------------------------\n
time_total: %{time_total}\n
使用示例:
curl -o /dev/null -s -w "@curl-format.txt" "https://const.net.cn/"
输出结果:
time_namelookup:0.165160
time_connect:0.240436
time_appconnect:0.326137
time_redirect:0.000000
time_pretransfer:0.326211
time_starttransfer:0.412927
------------------------------
time_total: 0.486244
本文链接地址:https://const.net.cn/23.html