Curl获取相关数据

Curl获取相关数据

使用cur  -w/--write-out l获取相关数据

几个比较关键的参数:

url_effective 最后获取的URL。
http_code 上一次HTTP(S)或FTP(S)操作返回的响应码。在7.18.2版加入的response_code显示同样的信息。
http_connect 在最后一次对cURL的CONNECT请求的响应(从代理)中发现的数值代码。 (在7.12.4版加入)
time_total 全部操作耗费的时间,单位为秒。精确到毫秒。
time_namelookup 从开始到域名解析完成耗费的时间,单位为秒。
time_connect TCP连接远程主机(或代理服务器)所耗时间,单位为秒。
time_appconnect SSL/SSH/等与远程主机连接/握手完成花费的时间,单位为秒。(在7.19.0 版加入)
time_pretransfer 从开始到文件将要传输前花费的时间,单位为秒。包括指定的协议所有预传输命令和negotiations。
time_redirect 所有重定向步骤的时间,包域名解析、连接、预传输和最后事务开始前的传输,单位为秒。time_redirect显示多重重定向的完整执行时间。(在7.12.3版加入 )
time_starttransfer  从开始到第一个字节将被传输前耗费的时间,单位为秒。
这包括time_pretransfer和服务器需要的运算结果的时间。
size_download下载的总字节数。
size_upload上传的总字节数。
size_header 下载的header的总字节数。
size_request 发送的HTTP请求的总字节数。
speed_download curl成功下载的平均下载速度。
speed_upload curl成功上传的平均上传速度。

 


3.获取请求的耗时信息


针对特定的请求,通过curl可以获取到各个环节的耗时情况,
比如域名解析的耗时,建立连接的耗时,服务端处理的耗时,总的耗时。


国内某合作方素材

curl -o /dev/null -s -w "http_code: %{http_code}\nhttp_connect:%{http_connect}\ncontent_type:%{content_type}\ntime_dns:%{time_namelookup}\ntime_redirect:%{time_redirect}\ntime_pretransfer:%{time_pretransfer}\ntime_connect:%{time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_total}:\nspeed_download:%{speed_download}\n " "http://di.adsame.com/flv_test/20161107143341_231.jpg";

http_code: 200
http_connect:000
content_type:image/jpeg
time_dns:0.005
time_redirect:0.000
time_pretransfer:0.013
time_connect:0.013
time_starttransfer:0.021
time_total:0.029:
speed_download:441815.000

苹果官网图片素材

curl -o /dev/null -s -w "http_code: %{http_code}\nhttp_connect:%{http_connect}\ncontent_type:%{content_type}\ntime_dns:%{time_namelookup}\ntime_redirect:%{time_redirect}\ntime_pretransfer:%{time_pretransfer}\ntime_connect:%{time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_total}:\nspeed_download:%{speed_download}\n " "http://images.apple.com/v/iphone-7/d/images/overview/design_hero_large.jpg";

http_code: 200
http_connect:000
content_type:image/jpeg
time_dns:0.449
time_redirect:0.000
time_pretransfer:0.456
time_connect:0.456
time_starttransfer:0.465
time_total:0.493:
speed_download:419293.000
 

微博短域名链接

curl -o /dev/null -s -w "http_code: %{http_code}\nhttp_connect:%{http_connect}\ncontent_type:%{content_type}\ntime_dns:%{time_namelookup}\ntime_redirect:%{time_redirect}\ntime_pretransfer:%{time_pretransfer}\ntime_connect:%{time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_total}:\nspeed_download:%{speed_download}\n "  -L "http://t.cn/Rip1YJA"

http_code: 200
http_connect:000
content_type:text/html;charset=GBK
time_dns:0.210
time_redirect:0.079
time_pretransfer:0.240
time_connect:0.240
time_starttransfer:0.290
time_total:0.369:
speed_download:4349.000
 

4.其他

目前只能用curl获取到指定请求的静态页面,还是无法像浏览器那样将页面中的链接都请求到,
这样就无法真实反应浏览器中访问页面的耗时情况。
不过当用户反映访问某个页面慢的时候,
通过curl访问对应的地址基本上可以确定,
单个请求主要耗时在哪里

转载于:https://www.cnblogs.com/miaoxg/p/7442001.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值