PHP Redirect unless site down

Started by kanen, February 12, 2011, 12:39:44 PM

Previous topic - Next topic

kanen

(for those who have been asking)



I created this because I am redirecting all traffic from port 80 to port 8080. Port 8080 runs a newLisp web server and DragonFly, but it could be running anything.



Sometimes, for whatever reason, my ISP decides to kill the newLisp process.



So, this redirects people to a "maint.html" page when that happens.



I hope this is as useful for everyone else as it has been for me.



Plus, it's super fast and simple PHP code.


<?php
       $site
= "www.mysite.com";
       
$port = 8080;
       
$fp = fsockopen($site,$port,$errno,$errstr,10);
       if(!
$fp)
       {
               
$fd = fopen("maint.html", r);
               
$content = fread($fd, filesize("maint.html"));
               
fclose($fd);
               echo
$content;
       }
       else{
               
header("Location: http://www.mysite.com:8080");
               
//echo "Connect was successful - no errors on Port ".$port." at ".$site;
               
fclose($fp);
               exit;
       }
       
//
?>
. Kanen Flowers http://kanen.me[/url] .