Created
December 13, 2016 19:53
-
-
Save cynovg/beedd2fe9fd1ddbca966345df1d3037d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 strict; | |
| use warnings; | |
| use AnyEvent::HTTP::LWP::UserAgent; | |
| use Data::Dump; | |
| use Time::HiRes; | |
| STDOUT->autoflush; | |
| my $ua = AnyEvent::HTTP::LWP::UserAgent->new; | |
| my $ae = AnyEvent->condvar; | |
| my %res; | |
| $ae->begin; | |
| while (my $url = <STDIN>) { | |
| chomp $url; | |
| $ae->begin; | |
| $res{ $url }->{'time'} = Time::HiRes::time(); | |
| $ua->get_async($url)->cb(sub{ | |
| my $r = shift->recv; | |
| $res{ $url }->{'time'} = Time::HiRes::time() - $res{ $url }->{'time'}; | |
| $res{ $url }->{'code'} = $r->code; | |
| printf "GET RESPONSE CODE %d FOR %s\n", $r->code, $url; | |
| $ae->end; | |
| }); | |
| } | |
| $ae->end; | |
| $ae->recv; | |
| dd \%res; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example: $cat list.txt | ./get_response.pl