PDA

View Full Version : php: how to check if a site is down and redirect...



simone.brunozzi
October 30th, 2006, 09:47 AM
Hi there,
I have a problem:

sometimes my website "Foo" is down;
the webdomain "Bar" point to another server, that is always up. On that server, however, I can't install the software I'm using on "Foo".
So, I use a redirect from the website root folder on "Bar" to the "Foo" directory.

When the "Foo" is down, I would like to redirect to a courtesy page, using php.
In other words, I need to write a PHP script that checks if a website is reachable and then, if not, redirects to a page.

Any help on that?

Thanks

nimrod_abing
October 30th, 2006, 01:57 PM
Hi there,
I have a problem:

sometimes my website "Foo" is down;
the webdomain "Bar" point to another server, that is always up. On that server, however, I can't install the software I'm using on "Foo".
So, I use a redirect from the website root folder on "Bar" to the "Foo" directory.

When the "Foo" is down, I would like to redirect to a courtesy page, using php.
In other words, I need to write a PHP script that checks if a website is reachable and then, if not, redirects to a page.

Any help on that?

Thanks

You can use the fsockopen() (http://www.php.net/manual/en/function.fsockopen.php) function. Set the timeout parameter to a reasonable value, say 10 seconds. If fsockopen() returns FALSE, then check errno and errstr and act accordingly on the results.

simone.brunozzi
November 7th, 2006, 10:00 PM
Sorry for the late answer!

Thanks, it seems to work!!

Simone