2ge has asked for the wisdom of the Perl Monks concerning the following question:
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++; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP::Parallel in other way
by PodMaster (Abbot) on Nov 01, 2004 at 14:54 UTC | |
by 2ge (Scribe) on Nov 01, 2004 at 15:17 UTC | |
by PodMaster (Abbot) on Nov 01, 2004 at 15:21 UTC | |
by 2ge (Scribe) on Nov 01, 2004 at 22:00 UTC | |
by 2ge (Scribe) on Nov 01, 2004 at 22:44 UTC | |
by PodMaster (Abbot) on Nov 02, 2004 at 13:43 UTC | |
|