curl 命令 检测耗时

这篇博客介绍了如何利用curl命令详细检测HTTP请求的各个阶段耗时,包括name lookup、connect、SSL handshake、pretransfer、redirect、firstbyte和total等时间指标,帮助理解网络请求的性能瓶颈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

curl -L --output /dev/null --silent --show-error -w \
'\nhttp code:    %{http_code}
namelookup:    %{time_namelookup}
connect:      %{time_connect}
sslhandshake:  %{time_appconnect}
pretransfer:  %{time_pretransfer}
redirect:      %{time_redirect}
firstbyte:    %{time_starttransfer}
total:        %{time_total}\n' \
http://www.baidu.com
# -v 选项,--verbose,指定该选项后,可以跟踪URL的连接信息。
# 加上选项后返回的信息,包括很多重要信息:

# 域名解析过程:我们可以得到真正连接的IP地址和端口
# 请求头信息:其中有使用的协议(HTTP),协议的请求方式(GET)
# 回应头信息:包含状态码,内容格式、长度等

说明

%{http_code},接口状态码
%{time_total}, 从开始到请求完毕的时间,响应完毕
%{time_namelookup},从开始到dns解析完成的时间
%{time_connect},从开始到链接完成的时间
%{time_pretransfer}, 从开始到请求开始传输的时间
%{time_appconnect}, 从开始到tls,ssl建立链接完毕的时间
%{time_starttransfer},从开始到第一个字节开始传输的时间

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.

机翻

namelookup - 从开始到完成名称解析所需的时间,以秒为单位。
connect - 从开始到完成与远程主机(或代理)的TCP连接所花费的时间,以秒为单位。
sslhandshake - 从开始到完成与远程主机的SSL/SSH/等连接/握手所花费的时间,以秒为单位。(在7.19.0中添加)
pretransfer - 从开始到文件传输即将开始所花费的时间,以秒为单位。这包括所有传输前的命令和特定协议所涉及的协商。
redirect - 所有重定向步骤的时间,以秒为单位,包括名称查找,连接,预传输和传输之前的最终事务开始。
firstbyte - 从开始到第一个字节即将被传输的时间,以秒为单位。这包括time_pre-transfer,也包括服务器需要计算结果的时间。
total - 整个操作所持续的总时间,以秒为单位。时间将以毫秒的分辨率显示。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值