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

The LWP man page states:
The timeout specifies how much time we give remote servers to respond before the library disconnects and creates an internal time- out response.
However, inspecting the code and searching google and this site as well, I don't see how to detect that this internal timeout response has been created. That is, what should I replace MAGIC with in the below code:
$response = $ua->request($r); if (MAGIC) { print "timed out\n"; } elsif ($response->is_success) { print "yippeeeeeeeee!\n"; }

Replies are listed 'Best First'.
Re: detecting timeout in LWP
by webfiend (Vicar) on Jul 30, 2007 at 22:34 UTC

    The status line should contain timeout details. Mine looked like this after a test run:

    500 Can't connect to mypoorcomputer.org (connect: timeout)
    # ... $ua->timeout(10); my $response = $ua->request($r); if ($response->is_success) { print "whee.\n"; } elsif ($response->status_line =~ /timeout/) { die "Timed out\n"; } else { die $response->status_line; }