Forum Moderators: coopster & phranque

Message Too Old, No Replies

LWP - get function

         

cubic

5:21 pm on Sep 26, 2004 (gmt 0)

10+ Year Member



How do I prevent from LWP::Simple 'get' function to stuck when web site is down? I tried both methods, but nothing seems to work out:

my $content = get( $url ) or next;

my $content = get( $url );

if (! defined $content )
{
print "Cannot get $url ($!)\n";
sleep(5);
next;
}

When the script reachers a web-site which is down, it just stucks on get( $url ).

Romeo

5:49 pm on Sep 26, 2004 (gmt 0)

10+ Year Member



Hi Cubic,

use the abstract web browser $ua of LWP
use LWP::Simple qw(get $ua);
However, if you do this, you have do export everything you want to use.
$ua->agent('My agent/1.0');
$ua->timeout(30); # time out after 30 seconds
my $content = get $url ¦¦ die "Timed out!";

More reading here:
[perldoc.strangesoft.net...]
[perlmonks.thepen.com...]

Regards,
R.

cubic

10:06 pm on Sep 26, 2004 (gmt 0)

10+ Year Member



Thanks! That's exactly what I was looking for.