Linux URL卷曲计时

Linux URL卷曲计时,linux,redirect,curl,timing,Linux,Redirect,Curl,Timing,我正在编写一个脚本来输出获取页面的总时间 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总时间为3秒 www.chinesegooseberry.com重定向至www.kiwifruit.com总时间为3秒

我正在编写一个脚本来输出获取页面的总时间

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总时间为3秒

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

但实际情况是这样的 www.chinesegooseberry.com(重定向时间为1.5秒) www.kiwifruit.com(3秒) 所以它应该给我4.5秒的总时间


有什么想法吗?

这个快速的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);
}
对于在命令行上传递的每个url,它将以秒为单位给出响应时间(端到端),作为浮点数


希望这对您有用。

此快速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);
}
对于在命令行上传递的每个url,它将以秒为单位给出响应时间(端到端),作为浮点数


希望这对您有用。

谢谢,将为您提供bash或perlThanks,将为您提供bash或perl