PHP Redirect unless site down

Q&A's, tips, howto's
Locked
kanen
Posts: 145
Joined: Thu Mar 25, 2010 6:24 pm
Contact:

PHP Redirect unless site down

Post by 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.

Code: Select all

<?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 .

Locked