Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Syntactic Confectionery Delight
 
PerlMonks  

LWP timeout

by dchau (Novice)
on Apr 02, 2001 at 13:47 UTC ( [id://68995]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

dchau has asked for the wisdom of the Perl Monks concerning the following question:

Hi this is my first time posting. I was wondering if there was a way to do something based on the LWP timeout function. For example:
foreach (@url){ chomp; $site = "$_"; $time = time(); $ua->timeout(30); $request = new HTTP::Request POST => $site; $response = $ua->request($request); $return_code = $response->code([$code]); &check_status($site, $return_code, $time); }
I want to do something when the request times out. Sort of like:
if ($ua->timeout(30)){ Write to log }
is this possible? with the timeout function? Thanks in advance.

Replies are listed 'Best First'.
Re: LWP timeout
by Jouke (Curate) on Apr 02, 2001 at 13:57 UTC
    Something like this should be possible:
    $ua -> timeout(45); $SIG{'ALRM'} = sub { die ("Timeout after 45 seconds"); };
    So you first set the timeout to 45 seconds and afterwards you connect the 'ALRM' signal to a subroutine that deals with what to do with it...

    Jouke Visser, Perl 'Adept'
      You must be warned of one potential pitfall :

      The timeout may seem to NOT work, if the host you're trying to connect is unreachable
      (you may wait long minutes whatever the number of seconds you used in your timeout() function...)
      See this post for more info.


      "Only Bad Coders Badly Code In Perl" (OBC2IP)
Re: LWP timeout
by THRAK (Monk) on Apr 02, 2001 at 14:02 UTC
    You could parse $response and look for a "408 Request Timeout" from the server. If you are LWPing, this might be useful either now or in the future.

    -THRAK
    www.polarlava.com
Re: LWP timeout
by dchau (Novice) on Apr 02, 2001 at 14:49 UTC
    I tried parsing the $response that doesnt work and i tried
    $timeout = 0; foreach (@url){ chomp; $site = "$_"; $time = time(); $ua->timeout(2); $SIG{'ALRM'} = sub {$timeout =1;}; $request = new HTTP::Request POST => $site; $response = $ua->request($request); $return_code = $response->code([$code]); print "return code = $return_code\n"; print "timeout = $timeout\n"; &check_status($site, $return_code, $time);
    When i print out $timeout it remains 0 doesnt change to 1 when the request times out

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://68995]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.