Skip to content

Instantly share code, notes, and snippets.

@cynovg
Created December 13, 2016 19:53
Show Gist options
  • Select an option

  • Save cynovg/beedd2fe9fd1ddbca966345df1d3037d to your computer and use it in GitHub Desktop.

Select an option

Save cynovg/beedd2fe9fd1ddbca966345df1d3037d to your computer and use it in GitHub Desktop.
#!/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;
@cynovg
Copy link
Author

cynovg commented Dec 13, 2016

example: $cat list.txt | ./get_response.pl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment