use strict; use warnings; use LWP::Parallel::UserAgent; my $http = 'http://2ge.mine.nu/headers.php'; my $max_hosts = 10; #registration of PARALLEL USER AGENT my $pua = LWP::Parallel::UserAgent->new(); $pua->in_order (0); # handle requests in order $pua->duplicates(0); # ignore duplicates $pua->timeout (10); # in seconds $pua->redirect (0); # follow redirects $pua->max_hosts ($max_hosts); # connect in parallel server $pua->max_req ($max_hosts); # max req per host my $counter = 0; my @agents = map "My agent $_", 1..15; for (my $i=0; $counter<@agents; $i++) { my @reqs_l = (); for (my $j=0; $j<$max_hosts; $j++) { push( @reqs_l,HTTP::Request->new('GET', $http) ); } my $reqs = \@reqs_l; #this could be better? foreach my $req (@$reqs) { if (defined $agents[$counter]) { $pua->agent("$agents[$counter]"); print "Registering agent: ".$counter."\n"; if ( my $res = $pua->register ($req) ) { print STDERR $res->error_as_HTML; } } $counter++; } my $entries = $pua->wait(); my $cnt = 0; foreach (keys %$entries) { print "WRITING content to $cnt.txt\n"; open(OUT,">$cnt.txt"); my $res = $entries->{$_}->response; print OUT $res->content( ); close OUT; $cnt++; } }