471,873 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

Problem with detecting error by LWP::UserAgent

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");
}

Jul 19 '05 #1
0 2816

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Woogie | last post: by
reply views Thread by Chandra | last post: by
2 posts views Thread by haimk63 | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.