最新消息:

使用curl来检测url耗时

Linux ipcpu 4570浏览

使用curl来检测url耗时.md

curl是一个很强大的工具,可以分析URL在各个阶段的耗时。使用方法如下:

# curl -L --output /dev/null --silent --show-error --write-out '\n\nnamelookup:    %{time_namelookup}\nconnect:      %{time_connect}\nsslhandshake:  %{time_appconnect}\npretransfer:  %{time_pretransfer}\nredirect:      %{time_redirect}\nfirstbyte:    %{time_starttransfer}\ntotal:        %{time_total}\n\n\n'  http://www.qyer.com -x 106.2.6.210:80


namelookup:    0.000
connect:      0.190
sslhandshake:  0.000
pretransfer:  0.190
redirect:      0.000
firstbyte:    0.564
total:        0.564

现在很多网站都是用的HTTP,上面的方法用不了,可以使用curl新功能resolve(curl 7.21.3+)

# curl -L --output /dev/null --silent --show-error --write-out '\n\nnamelookup:    %{time_namelookup}\nconnect:       %{time_connect}\nsslhandshake:  %{time_appconnect}\npretransfer:   %{time_pretransfer}\nredirect:      %{time_redirect}\nfirstbyte:     %{time_starttransfer}\ntotal:         %{time_total}\n\n\n'  https://www.baidu.com/ --resolve "www.baidu.com:443:180.97.33.108"


namelookup:    0.023074
connect:       0.056913
sslhandshake:  0.379040
pretransfer:   0.379117
redirect:      0.000000
firstbyte:     0.415180
total:         0.415550

各个阶段耗时解释

namelookup - The time, in seconds, it took from the start until the name resolving was completed.

connect - The time, in seconds, it took from the start until the TCP connect to the remote host(or proxy) was completed.#

sslhandshake - 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)

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.

redirect - The time, in seconds, it took for all redirection steps include name lookup,connect,pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections.

firstbyte - The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pre-transfer and also the time the server needed to calculate the result.

total - The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.

转载请注明:IPCPU-网络之路 » 使用curl来检测url耗时