karthick has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use LWP::UserAgent; use HTTP::Request; use threads; my $url="http://www.google.com"; my %hash; my $dthread; my %shash; open FH,">result.txt"; my $numworkers=1000; while($numworkers) { foreach my $dthread(1..250) { $hash{$dthread} = threads->create(\&requester,$url); } foreach my $dthread(1..250) { $hash{$dthread}->join(); $numworkers--; } } } sub requester() { my $url1=shift; my $request = HTTP::Request->new(GET => $url1); my $ua = LWP::UserAgent->new; print "Requesting Header....\n\n"; my $response = $ua->request($request); print "Requesting placed....\n\n"; my $content=$response->headers_as_string; print FH "$content\n\n"; print " .........thread completed............\n\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Newbie question in threading
by Corion (Patriarch) on Apr 09, 2010 at 11:21 UTC | |
by karthick (Initiate) on Apr 09, 2010 at 11:36 UTC | |
|
Re: Newbie question in threading
by BrowserUk (Patriarch) on Apr 09, 2010 at 11:36 UTC |