View Single Post
Old 05-09-2007   #8 (permalink)
Mikko Noromaa


 
 

Re: BUG: All http access blocked after running Perl script

Thanks, I'll check if my real app has the same inefficiency.

--

Mikko Noromaa (mikkon@excelsql.com)
- SQL in Excel, check out ExcelSQL! - see http://www.excelsql.com -

"Scissor" <Scissor.2qbzx7@no-mx.forums.net> wrote in message
news:Scissor.2qbzx7@no-mx.forums.net...
>
> Not that this matters, but I noticed that your test script is a little
> inefficient because it recreates the LWP::UserAgent and HTTP::Request
> objects for each iteration of the while loop.
>
> You should be able to create the objects just once ahead of time and
> then reuse the objects inside the while loop. Below is an updated
> script explaining my suggestion.
>
> Note that the suggested changes should not have any effect on the
> possible bug you originally reported.
>
>
>
> Code:
> --------------------
>
> #!perl
>
> use strict;
> use warnings;
> use LWP::UserAgent;
>
> my $n = 1;
> my $ua = LWP::UserAgent->new;
> my $req = HTTP::Request->new(GET => "http://127.0.0.1/test.htm");
> $req->header('Accept' => 'text/html');
>
> while (1) {
> print "Fetching page $n...";
> my $res = $ua->request($req);
>
> if ($res->is_success) {
> print " OK!\n";
> $n++;
> }
> else {
> print " ERROR: " . $res->status_line . ".\n";
> sleep 1;
> }
> }
>
> --------------------
>
>
> --
> Scissor



My System SpecsSystem Spec