2012-04-04 93 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