curl 时间变量格式化输出

默北 Linux221,9738字数 930阅读3分6秒阅读模式
摘要

获取站点的各类响应时间,可以去看看前面写的文章。

获取站点的各类响应时间,可以去看看前面写的文章。

对curl时间变量的格式化输出。文章源自运维生存时间-https://www.ttlsa.com/linux/curl-time-variable-formatted-output/

定义格式化文件

#vim  curl-format.txt 
\n
            time_namelookup:  %{time_namelookup}\n
               time_connect:  %{time_connect}\n
            time_appconnect:  %{time_appconnect}\n
           time_pretransfer:  %{time_pretransfer}\n
              time_redirect:  %{time_redirect}\n
         time_starttransfer:  %{time_starttransfer}\n
                            ----------\n
                 time_total:  %{time_total}\n
\n

这些变量的含义不解释了,大伙去看看curl帮助文档。重点说下time_connect和time_appconnect变量。time_connect 变量表示 TCP 握手的耗时,time_appconnect 变量表示 SSL 握手的耗时(ssl延时)。HTTPs 连接耗时要比 HTTP 连接耗时长 3 倍左右,具体取决于 CPU 的快慢。文章源自运维生存时间-https://www.ttlsa.com/linux/curl-time-variable-formatted-output/

发送请求

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

            time_namelookup:  0.002
               time_connect:  1.973
            time_appconnect:  0.000
           time_pretransfer:  1.973
              time_redirect:  0.000
         time_starttransfer:  3.126
                            ----------
                 time_total:  5.374

# curl -w "@curl-format.txt" -o /dev/null -s  https://www.baidu.com

            time_namelookup:  0.003
               time_connect:  1.705
            time_appconnect:  4.007
           time_pretransfer:  4.007
              time_redirect:  0.000
         time_starttransfer:  5.214
                            ----------
                 time_total:  5.214

-w 指定格式化文件文章源自运维生存时间-https://www.ttlsa.com/linux/curl-time-variable-formatted-output/

-o 请求重定向到文章源自运维生存时间-https://www.ttlsa.com/linux/curl-time-variable-formatted-output/

-s 静默,不现实进度
文章源自运维生存时间-https://www.ttlsa.com/linux/curl-time-variable-formatted-output/ 文章源自运维生存时间-https://www.ttlsa.com/linux/curl-time-variable-formatted-output/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 02/07/2015 11:38:31
  • 转载请务必保留本文链接:https://www.ttlsa.com/linux/curl-time-variable-formatted-output/
评论  2  访客  2
    • af
      af 1

      不错,学习了。

      • 匿名
        匿名 9

        很实用

      评论已关闭!