in reply to Problems trying to timeout LWP requests

There's a much easier way to do this - You can set the timeout for the connection by calling the timeout method on your LWP::UserAgent object.

For example:

my $ua = LWP::UserAgent->new; $ua->timeout(3); # Sets a three-second timeout

By default, this timeout method is set to 180 seconds (3 minutes) - This is described in the LWP documentation. Additionally, the use_alarm method can be used to set/get a value indicating whether to use alarm when implementing timeouts - This is useful if you make use of alarm elsewhere in your applications.

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Replies are listed 'Best First'.
Re: Re: Problems trying to timeout LWP requests
by tomhukins (Curate) on Feb 06, 2002 at 12:43 UTC
      The request is working and the host is responding okay but for purposes of testing the timeout I have chosen a value sufficiently low that the request should be cancelled anyway.

      I have looked at the results of Super Search and I believe this is a common question to which nobody has been able to give a satisfactory answer.

      I have now emailed Gisle Aas to see if he can throw any light on the question.

      Cheers

      Cheshire Cat

Re: Re: Problems trying to timeout LWP requests
by cheshirecat (Sexton) on Feb 06, 2002 at 12:47 UTC
    I've tried using $ua->timeout(3); and it does not work for me,
    this was why I was trying the alarm method.

    As for use_alarm, see the code below from UserAgent.pm

    # depreciated sub use_eval { shift->_elem('use_eval', @_); } sub use_alarm { Carp::carp("LWP::UserAgent->use_alarm(BOOL) is a no-op") if @_ > 1 && $^W; ""; }

    It appears that the documentation is out of date as this method is now depreciated.

    Cheers

    Cheshire Cat