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