cURL学习

2010-08-10

今天,学习了下curl。

主要是使用curl 来分析网站的打开速度。

curl -w 参数可以查看 网站具体的打开速度。只有了解具体那个环节慢才能做优化!

man curl 简单解读下 -w 这个参数下几个今天用到的参数。

-w/--write-out

time_total 这个参数是总时间,意思就是打开一个页面所占用的所有时间。

time_namelookup 字面意思就可以明白了,是dns查询所占用的时间。

time_connect 与服务建立连接的时间。

示例,以www.hao123.com 为分析对象,呵呵:

    curl -w "time_total\t%{time_total}\ntime_namelookup\t%{time_namelookup}\ntime_connect\t%{time_connect}\n" \
    www.hao123.com -o /dev/null

time_total 0.339

time_namelookup 0.015

time_connect 0.048

为了方便,简单写了个shell方便以后使用

    #!/bin/bash
    cURL='/usr/bin/curl';
    $cURL -w "time_total\t%{time_total}\ntime_namelookup\t%{time_namelookup}\ntime_connect\t%{time_connect}\n" \
    $1 -o /dev/null