vonersnae has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Thread::Pool; use WWW:Mechanize; my %check :shared = ('success', 0, 'fail', 0, 'exit', 0); my $pool = Thread::Pool->new( { optimize => 'memory', workers => 1, do => \&request, } ); for(1..10){ $pool->job(); $pool->add; { print "Please type 'exit' to quit: "; chomp ($_=<STDIN>); if($_=~/exit/i){ $check{exit} = 1; $pool->shutdown;} print "success: $check{success}\tfailed: $check{fail}\n"; sub request{ my $flag = 0; my $mech = WWW::Mechanize->new(autocheck => 1); $mech->get('http://example_server.com/login.php'); $mech->submit_form( form_number =>1, fields =>{ username => 'testuser' password => '123qwe' } ); if($mech->uri() =~/home/i){ #check if login if successful $check{success}++; $flag = 1; } else { $check{fail}++;} while($check{exit} != 1 && $flag == 1){ $mech->follow_link( url_regex => qr/nextpage/i); $mech->get('http://example_server.com/home'); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simultaneous request using threading
by stiller (Friar) on Apr 11, 2008 at 07:50 UTC | |
|
Re: Simultaneous request using threading
by BrowserUk (Patriarch) on Apr 11, 2008 at 08:38 UTC | |
|
Re: Simultaneous request using threading
by Sinistral (Monsignor) on Apr 11, 2008 at 14:41 UTC | |
|
Re: Simultaneous request using threading
by vonersnae (Novice) on Apr 12, 2008 at 03:03 UTC | |
|
Re: Simultaneous request using threading
by vonersnae (Novice) on Apr 13, 2008 at 05:29 UTC | |
|
Re: Simultaneous request using threading
by Anonymous Monk on Apr 13, 2008 at 05:18 UTC |