Jump to content
xisto Community
Sign in to follow this  

Auto choosing primary or secondary server (Perl)

Recommended Posts

This script can be useful if you have two servers with your website and you hate breakdowns, it checks is the primary server available and redirects to primary or secondary server.

#!/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://primary.server/index.php');$req->content_type('application/x-www-form-urlencoded');$ua->timeout(10);my $res = $ua->request($req);if ($res->is_success) {  print $query->redirect("http://primary.server/index.php");} else {   print $query->redirect("http://secondary.server/index.php");}

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.