Order:
curl -o /dev/null -H "Cache-Control: no-cache" -s -w time_namelookup:"\t"%{time_namelookup}"\n"time_connect:"\t\t"%{time_connect}"\n"time_pretransfer:"\t"%{time_pretransfer}"\n"time_starttransfer:"\t"%{time_starttransfer}"\n"time_total:"\t\t"%{time_total}"\n"time_redirect:"\t\t"%{time_redirect}"\n" https://www.baidu.com
Results of the:
time_namelookup: 0.004
time_connect: 0.008
time_pretransfer: 0.119
time_starttransfer: 0.143
time_total: 0.143
time_redirect: 0.000
Detailed description:
Cache-Control: no-cache header, allowing the server to not use cache to satisfy requests and always provide the latest data
time_namelookup: calculated from the beginning, the time it takes to complete the domain name resolution
time_connect: calculated from the beginning, the time it takes to complete the TCP establishment (handshake)
time_pretransfer: Calculated from the beginning, the time taken to start transmitting data
time_starttransfer: Calculated from the beginning, the time taken to start transmitting data (libcurl receives the first byte)
time_total: The total time taken
time_redirect: The time taken for the entire process of redirection , if the entire process is not redirected, this time is 0
Curl's -w parameter description:
The -w parameter of curl is used to output the content in the specified format to the standard output after a complete and successful operation. The output format consists of an ordinary string and any number of variables. The output variables need to be in the format of %{variable_name}.
For example, to get only the http status code, you can do this:
复制代码
curl -w %{http_code} www.baidu.com -o /dev/null -s |
To get the time of the entire request, you can do this:
复制代码
curl -w %{time_total} www.baidu.com -o /dev/null -s |
To get the domain name resolution time, you can do this:
复制代码
curl -w %{time_namelookup} www.baidu.com -o /dev/null -s |
It takes time to obtain a TCP connection. You can do this:
复制代码
curl -w %{time_connect} www.baidu.com -o /dev/null -s |
In addition, there are other variables that can be used, such as url_effective, response_code, etc. More variables can be viewed in curl's official documentation.