in reply to
Slow HTTP::Async responses
How about using
AnyEvent::HTTP?
#!/usr/bin/perl
use strict;
use AnyEvent;
use AnyEvent::HTTP;
use Time::HiRes qw(time);
my $cv = AnyEvent->condvar(
cb => sub {
print "\n";
print "Starting test...\n";
print "\n";
}
);
my $urls = [
'http://www.google.com', 'http://www.yahoo.com',
'https://pause.perl.org', 'http://www.perlmonks.com',
'http://www.perl.com', 'http://www.cpan.org'
];
my $start = time;
my $result;
$cv->begin(
sub {
( shift() )->send($result);
}
);
foreach my $url (@$urls) {
$cv->begin;
my $now = time;
my $request;
$request = http_request(
GET => $url,
timeout => 3,
sub {
my ( $body, $hdr ) = @_;
if ( $$hdr{'Status'} =~ /^2/ ) {
push(
@$result,
join(
" ",
(
$url, "=> \n length",
$$hdr{'content-length'}, "\n loaded in",
time - $now, "ms"
)
)
);
}
else {
push(
@$result,
join( "",
"Error for ", $url, ": (",
$hdr->{Status}, ") ", $hdr->{Reason} )
);
}
undef $request;
$cv->end;
}
);
}
$cv->end;
my $foo = $cv->recv;
print join( "\n", @$foo ), "\n" if defined $foo;
print "\nTotal elapsed time: ", time - $start, "ms\n\n";
I got the idea
here.