-
-
Save dougwilson/0dbc430a67f28bac0b39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.12; | |
use warnings; | |
use Mojo::UserAgent; | |
use Mojo::IOLoop; | |
use Time::HiRes qw(time); | |
my $delay = Mojo::IOLoop->delay(sub { warn "done"; }); | |
my @urls = ( | |
"https://www.google.com", | |
"http://www.windley.com/", | |
"https://www.bing.com", | |
"http://www.example.com", | |
"http://www.wetpaint.com", | |
"http://www.uh.cu", | |
); | |
my $ua = Mojo::UserAgent->new(max_redirects => 3); | |
my $start = time; | |
foreach my $u (@urls) { | |
$delay->begin; | |
my $now = time; | |
$ua->get($u => sub { | |
my($ua, $tx) = @_; | |
my $u = sprintf "%-25s", $u; | |
my $et = sprintf "%5.3f", time - $now; | |
my $len = sprintf "%8s", length($tx->res->body); | |
$delay->end($tx->success | |
? "$u has length $len and loaded in $et ms" | |
: sprintf "Error for $u: (%s) %s", $tx->error | |
); | |
}); | |
} | |
warn "End of loop\n"; | |
say for $delay->wait; | |
my $tet = sprintf "%5.3f", time - $start; | |
say "Total elapsed time: $tet ms"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've enabled redirects in the example now.