2012-04-04 94 views
1

我正在编写一个脚本来输出获得页面的总时间。URL卷曲计时

curl -I -L -o /dev/null -w "Connect: %{time_connect}: TTFB: %{time_starttransfer} Total time: %{time_total} \n" $1 2>/dev/null 

但是我遇到的问题是,它返回到最终URL的时间。

www.apple.com时间总是3secs

www.chinesegooseberry.com 重定向到www.kiwifruit.com总时间3秒

但在实际条款它像 www.chinesegooseberry.com(1.5秒重定向) www.kiwifruit.com(3秒) 所以它应该给我4.5秒的总时间

有什么想法?

回答

1

这种快速perl脚本可能会有所帮助:

#! /usr/bin/perl 

use LWP::UserAgent; 
use Time::HiRes qw/&time/; 

sub timereq { 
    my ($url) = @_; 
    my $ua = LWP::UserAgent->new; 
    $ua->requests_redirectable ([qw/GET POST/]); 
    my $start = time; 
    my $ret = $ua->get($url); 
    if ($ret->is_success()) { 
     return time-$start; 
    } 
    print STDERR "req to $url failed\n" unless $ret->is_success(); 
    return undef; 
} 

$| = 1; 

foreach my $url(@ARGV) { 
    printf("%6.3f %s\n",timereq($url),$url); 
} 

对于在命令行上传递的每个网址,它会给响应时间(终端到终端)以秒为一个浮点数。

希望这对你有用。

+0

谢谢,会给这个bash或perl – sauj 2012-04-23 16:30:51