Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Slow HTTP::Async responses

by Khen1950fx (Canon)
on Feb 14, 2013 at 21:04 UTC ( #1018792=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: Slow HTTP::Async responses
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018792]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-08-29 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls