linux - URL curl 时间

标签 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 秒

但实际上它是这样的 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,它将以秒为单位给出响应时间(端到端),作为 float 。

希望这对你有用。

关于linux - URL curl 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10010193/

相关文章:

linux - 包括 <linux/spinlock.h> 链接器

linux - 为 Armv7 汇编程序打印换行符

c++ - 将 C++ 生成的 cerr 和 cout 重定向到 Ubuntu 中的同一文件

curl:(7)无法连接到172.17.0.8端口80:连接被拒绝

post - curl 发布数据和文件当代

c++ - CBLAS_ORDER 不是 gcc 的类或命名空间,但在 VS2010 (Intel C++) 中编译良好

linux - 如何设置默认的ping6接口(interface)

javascript - 如果表单提交成功并在页面上保留其错误,如何使用js进行重定向

c++ - 我的重定向机制有什么问题?

php - HTTP 请求失败! HTTP/1.1 505 HTTP 版本不受支持错误