linuxea:curl常用命令

marksugar
2022-06-15 / 0 评论 / 1,377 阅读 / 正在检测是否收录...

curl常用命令
time_connect : 建立到服务器的 TCP 连接所用的时间
time_starttransfer: 在发出请求之后,Web 服务器返回数据的第一个字节所用的时间
time_total: 完成请求所用的时间

在 发出请求之后,Web 服务器处理请求并开始发回数据所用的时间是

(time_starttransfer)1.044 - (time_connect)0.244 = 0.8 秒

客户机从服务器下载数据所用的时间是

(time_total)2.672 - (time_starttransfer)1.044 = 1.682 秒

指定特定主机IP地址访问网站
curl -x 61.1315.169.105:80 http://www.baidu.com
curl -x 61.1315.169.125:80 http://www.baidu.com

网页响应时间

curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "http://www.linuxea.com"

time_connect: 0.009
time_starttransfer: 0.357
time_total: 0.358

状态返回码

curl -s -w %{http_code} "http://www.baidu.com"

完成请求所用的时间

curl -o /dev/null -s -w '%{time_total}' http://www.linuxea.com
0.456

或者如下

curl -o /dev/null -s -w "%{http_code}\n%{time_connect}\n%{time_starttransfer}\n%{time_total}" http://www.baidu.com
200
0.038
0.071
0.071

文件

创建一个新文件 curl-format.txt,然后粘贴:

     time_namelookup:  %{time_namelookup}s\n
        time_connect:  %{time_connect}s\n
     time_appconnect:  %{time_appconnect}s\n
    time_pretransfer:  %{time_pretransfer}s\n
       time_redirect:  %{time_redirect}s\n
  time_starttransfer:  %{time_starttransfer}s\n
                     ----------\n
          time_total:  %{time_total}s\n
  1. 发出请求:

     curl -w "@curl-format.txt" -o /dev/null -s "http://wordpress.com/"

或者在 Windows 上,它是...

    curl -w "@curl-format.txt" -o NUL -s "http://wordpress.com/"

这是做什么的:

-w "@curl-format.txt"告诉 cURL 使用我们的格式文件
-o /dev/null将请求的输出重定向到 /dev/null
-s 告诉 cURL 不要显示进度表
"http://wordpress.com/"是我们请求的 URL。如果您的 URL 具有“&”查询字符串参数,请特别使用引号

输出

   time_namelookup:  0.001s
      time_connect:  0.037s
   time_appconnect:  0.000s
  time_pretransfer:  0.037s
     time_redirect:  0.000s
time_starttransfer:  0.092s
                   ----------
        time_total:  0.164s

制作 Linux/Mac 快捷方式(别名)

alias curltime="curl -w \"@$HOME/.curl-format.txt\" -o /dev/null -s "

然后你可以简单地调用...

curltime wordpress.org
0

评论

博主关闭了所有页面的评论