使用curl进行网站测速

本文介绍了如何使用curl命令行工具进行网站速度测试,详细解释了curl的--time-cond选项,以及它如何显示各阶段的耗时,帮助优化网站速度。通过示例展示了时间变量的对应关系和实际输出结果。
摘要由CSDN通过智能技术生成

原文地址:https://www.lujun9972.win/blog/2021/06/08/使用curl进行网站测速/index.html

网站访问可以分为下面几个阶段:

  • DNS 域名解析
  • 通过SSL协议交换密钥(HTTPS)
  • 与服务端创建 TCP 访问连接
  • 客户端发起请求
  • 服务端收到请求并准备回应内容
  • 服务端回复回应内容

当我们优化网站速度时通常要现确定哪个阶段是耗时大头。而令我感到惊奇的是,原来 curl 的 -w 选项可以让 curl 完成访问网站的操作后将各阶段的耗时情况(以及其他一些访问信息)输出到标准输出。

man curl 中关于 -w 选项的说明如下:

-w, --write-out <format>
       Make curl display information on stdout after a completed trans‐
       fer. The format is a string that may contain  plain  text  mixed
       with  any  number of variables. The format can be specified as a
       literal "string", or you can have curl read the  format  from  a
       file  with  "@filename" and to tell curl to read the format from
       stdin you write "@-".

       The variables present in the output format will  be  substituted
       by  the  value or text that curl thinks fit, as described below.
       All variables are specified as %{variable_name} and to output  a
       normal  % you just write them as %%. You can output a newline by
       using \n, a carriage return with \r and a tab space with \t.

       NOTE: The %-symbol is a special symbol in the win32-environment,
       where  all  occurrences  of  %  must  be doubled when using this
       option.

       The variables available are:

       content_type   The Content-Type of the  requested  document,  if
                      there was any.

       filename_effective
                      The  ulti
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值