multi-threading

Discussion in 'Perl Misc' started by Jason Quek, Dec 3, 2003.

  1. Jason Quek

    Jason Quek Guest

    Hi

    I have a long list of URLs and I need to do HTTP requests for each of
    these domains.

    # -----------------------------------------------------------------
    @urls = (
    'http://www.yahoo.com',
    'http://www.google.com',
    'http://www.msn.com',
    'http://www.altavista.com'
    );

    use LWP::UserAgent;
    $ua = LWP::UserAgent->new;

    foreach $url (@urls)
    {
    $req = HTTP::Request->new('GET', "$url");
    $results = $ua->request($req)->as_string;

    # then process $results
    }
    # -----------------------------------------------------------------

    How do I multi-thread so that multiple URLs are http-requested at the
    same time?

    Any help would be appreciated.

    Thank you



    Jason Q.
     
    Jason Quek, Dec 3, 2003
    #1
    1. Advertising

  2. In article <>,
    (Jason Quek) wrote:

    > How do I multi-thread so that multiple URLs are http-requested at the
    > same time?


    See LWP::parallel - its all done for you (and works _very_ well, thanks
    Marc!)

    http://search.cpan.org/~marclang/ParallelUserAgent-2.56/lib/LWP/Parallel.
    pm

    (watch the line wrapping on that)

    big

    --
    'When I first met Katho, she had a meat cleaver in one hand and
    half a sheep in the other. "Come in", she says, "Hammo's not here.
    I hope you like meat.' Sharkey in aus.moto
     
    Iain Chalmers, Dec 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    38
    Views:
    1,320
    Dennis Lee Bieber
    Feb 15, 2005
  2. Replies:
    9
    Views:
    1,126
    Mark Space
    Dec 29, 2007
  3. Steven Woody
    Replies:
    0
    Views:
    475
    Steven Woody
    Jan 9, 2009
  4. Steven Woody
    Replies:
    0
    Views:
    489
    Steven Woody
    Jan 9, 2009
  5. akineko
    Replies:
    3
    Views:
    2,731
    Jesse Noller
    Jan 29, 2009
Loading...

Share This Page