博文

目前显示的是标签为“curl”的博文

使用 curl 测试网站加载速度

curl 命令有一个鲜为人知的选项, -w ,该选项在请求结束之后打印本次请求的统计数据到标准输出。 首先,我们定义控制打印行为的格式化字符串。新建文本文件  fmt.txt ,并填入下面的内容: \n Response Time for: %{url_effective} \n\n DNS Lookup Time: \t\t %{time_namelookup} s\n Redirection Time: \t\t %{time_redirect} s\n Connection Time: \t\t %{time_connect} s\n App Connection Time: \t\t %{time_appconnect} s\n Pre-transfer Time: \t\t %{time_pretransfer} s\n Start-transfer Time: \t\t %{time_starttransfer} s\n\n Total Time: \t\t\t %{time_total} s\n curl 提供了很多置换变量,可以在格式化字符串中通过  %{var}  的形式使用。完整的变量列表可以在 curl 的 manpage 中查看。简单介绍一下我们使用的这几个变量: url_effective : 执行完地址重定向之后的最终 URL; time_namelookup : 从请求开始至完成名称解析所花的时间,单位为秒,下同; time_redirect : 执行所有重定向所花的时间; time_connect : 从请求开始至建立 TCP 连接所花的时间; time_appconnect : 从请求开始至完成 SSL/SSH 握手所花的时间; time_pretransfer : 从请求开始至服务器准备传送文件所花的时间,包含了传送协商时间; time_starttransfer : 从请求开始至服务器准备传送第一个字节所花的时间; time_total : 完整耗时。 然后执行请求,通过  @filename  指定保存了格式化字符串的文件: $ curl -L -s -w @fmt.txt -o /dev/null http://www.google....