zoukankan      html  css  js  c++  java
  • 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} http_connect:%{http_connect} content_type:%{content_type} time_dns:%{time_namelookup} time_redirect:%{time_redirect} time_pretransfer:%{time_pretransfer} time_connect:%{time_connect} time_starttransfer:%{time_starttransfer} time_total:%{time_total}: speed_download:%{speed_download} " "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} http_connect:%{http_connect} content_type:%{content_type} time_dns:%{time_namelookup} time_redirect:%{time_redirect} time_pretransfer:%{time_pretransfer} time_connect:%{time_connect} time_starttransfer:%{time_starttransfer} time_total:%{time_total}: speed_download:%{speed_download} " "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} http_connect:%{http_connect} content_type:%{content_type} time_dns:%{time_namelookup} time_redirect:%{time_redirect} time_pretransfer:%{time_pretransfer} time_connect:%{time_connect} time_starttransfer:%{time_starttransfer} time_total:%{time_total}: speed_download:%{speed_download} "  -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访问对应的地址基本上可以确定,
    单个请求主要耗时在哪里

  • 相关阅读:
    移动web技能总结
    canvas绘图基础
    如何自定义滚动条?
    学习笔记-AngularJs(十)
    学习笔记-AngularJs(九)
    硬盘杀手!Windows版Redis疯狂占用C盘空间【转】
    64位win10系统无法安装.Net framework3.5的两种解决方法【转】
    分享一个电子书地址
    阿里、腾讯、百度、华为、京东、搜狗和滴滴最新面试题汇集【转】
    jQuery时间轴
  • 原文地址:https://www.cnblogs.com/miaoxg/p/7442001.html
Copyright © 2011-2022 走看看