in reply to Getting html from more than one site simultaneously?
As an alternative to the other suggestions, you can use Parallel::ForkManager with LWP::Simple.
This is example code from 'man Parallel::ForkManager':
use LWP::Simple; use Parallel::ForkManager; ... @links=( ["http://www.foo.bar/rulez.data","rulez_data.txt"], ["http://new.host/more_data.doc","more_data.doc"], ... ); ... # Max 30 processes for parallel download my $pm = new Parallel::ForkManager(30); foreach my $linkarray (@links) { $pm->start and next; # do the fork my ($link,$fn) = @$linkarray; warn "Cannot get $fn from $link" if getstore($link,$fn) != RC_OK; $pm->finish; # do the exit in the child process } $pm->wait_all_children;
First you need to instantiate the ForkManager with the "new" constructor. You must specify the maximum number of processes to be created. If you specify 0, then NO fork will be done; this is good for debugging purposes.
Next, use $pm->start to do the fork. $pm returns 0 for the child process, and child pid for the parent process (see also perlfunc(1p)/fork()). The "and next" skips the internal loop in the parent process. NOTE: $pm->start dies if the fork fails.
$pm->finish terminates the child process (assuming a fork was done in the "start").
Hope that helps.
After Compline,
Zaxo
|
|---|