Problem with detecting error by LWP::UserAgent

P

Playker

Hello
I have a website on 2 servers. I want to make a script which checks is first
server availbale (he often breaks down) and redirects to 1st or 2nd server.
Script works well if an error is the 404 error, but it doesn't work if
server doesn't answer (and that's what I want). Can anyone help me? This is
the code:

#!/usr/bin/perl
##
##
##

use LWP::UserAgent;
use CGI;
$| = 1;
my $query = new CGI;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

my $req = HTTP::Request->new(GET => 'http://pierwszy.serwer/index.php');
$req->content_type('application/x-www-form-urlencoded');

my $res = $ua->request($req);

if ($res->is_success) {
print $query->redirect("http://first.server/index.php");
} else {
print $query->redirect("http://second.server/index.php");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top