Script that forwards you to a secondary server if main server is offline

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
Is there a script that I can use that would check if fye.x10hosting.com is up and if it is down send connections to a different URL? My members keep telling me my site is down. I'd like to send them to a little page on a different server that tells them the server is down and not to tell me. So all I need is the script that checks the status. Thanks for any help!
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
I'd host it on a different server that has very high uptime.
(1 minute after I posted you replied. wow)
 

YamiKaitou

Member
Messages
636
Reaction score
0
Points
16
Then it would require you to use a thing like Brandon's server status script that checks to see if the port is up. If it is, it directs them to one place, if not, then it directs them elsewhere
 

Torch

New Member
Messages
634
Reaction score
0
Points
0
Ok, I wrote you up a short script that will check status of one server and if it's up redirect you to it, and if it's not, redirect you to another server. Or, if you un/comment correspoding lines (header and echo), just displays the error messages. The best way to use it would be to give out address of the server (site) you know that'll be up all the time, put it as an index.php there, and than people would be redirected where needed depending of server statuses.
Ok, here it is...

PHP:
<?
error_reporting(0); // Disables error reporting
$URI = "google.com"; // Your main server address, can be IP too (DON'T PUT http://)
$URI2 = "x10hosting.com"; // Your second server address
$TO = 5; // Timeout in seconds
if(fsockopen($URI,80,$TO)){
   header("Location: http://$URI"); // Redirects to your server if it works
   //echo "Server is working perfectly!";
}
else{
   header("Location: http://$URI2"); // Redirects to your second server in case first one doesn't work
   //echo "We are currently having some troubles with the server, please come back later!";
}
?>
 
Last edited:

acidburn0520

New Member
Messages
117
Reaction score
0
Points
0
For this to work, you'd need an server to act as an intermediary or a gateway of sorts; if the server is online, let the user pass, and if not, display an error. Rather complicated just to give your users a page telling them the server is down.
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
Thanks Torch!!!
The script works fine if the main server is online, but otherwise firefox gives me a connection reset error. Any idea why?
 
Last edited:

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
Just Check this

PHP:
<?php
    error_reporting(0);
    $ip = "first ip address";
    $port = "port to check";

   $url = "url to  be redirected to";

    if (! $sock = @fsockopen($ip, $port, $num, $error, 5))
    {
?>
               <script language='javascript' type='text/javascript'>
                             location = <?php print $url; ?> ;
               </script>
<?php
    }
?>
 

Sohail

Active Member
Messages
3,055
Reaction score
0
Points
36
Where would you place that script as if it was on the first server and that was done then you wouldn't be able to execute the script so i'm guessing it will be placed on the second server and that every time the site is accessed it will go to the second server to run that script right?
 
Top