By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,657 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Ping A Page, Reddirect if Not Available

P: n/a
Originally posted with Comp.lang.php spelt stupidly incorrectly. Please
accept my apologies for the resultant multi-post....

Hi, I'm cross posting to comp.infosystems.www.authoring.html and
comp.languages.php. Our IT staff who usually do this sort of thing are
rather busy and I am desperately looking at an impending deadline.

My organization's web page is on a server which has php. A work request
web server is on a separate server which I take down frequently for
maintenance, upgrades and tweaking. What I'm trying to do is create a
page, which will be the link to the work request service, that will
first ping the work request server. If the work request service is
active, it will go to it. If it is down, it will redirect to another page.

Is there anywhere on the web which might have sample code for this sort
of thing? All of the suggestions I have be other knowledgeable
colleagues as well as google searches I have done so far either point to
VB scripting/ASP
(http://www.forum4designers.com/archi...-4-209035.html, for
example) or deal with PHP issues that don't seem to address my needs. My
coding knowledge of PHP is non-existent and my html skills are
rudimentary and I don't know anything about how to ping a server. As I
mentioned at the beginning, I'm kind of on my own due to a deadline.

Thanks very much in advance for any leads on this.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>My organization's web page is on a server which has php. A work request
web server is on a separate server which I take down frequently for
maintenance, upgrades and tweaking. What I'm trying to do is create a
page, which will be the link to the work request service, that will
first ping the work request server. If the work request service is
active, it will go to it. If it is down, it will redirect to another page.
"ping", assuming you mean that literally (ICMP packets), will not
tell you if the web server is up and able to serve pages. For
example, a web server may ping nicely while it is spending 15 minutes
running fsck cleaning its filesystems after a crashed caused by CPU
overheating due to fan failure, and the web server is not running
during this time.

Is there anywhere on the web which might have sample code for this sort
of thing? All of the suggestions I have be other knowledgeable
colleagues as well as google searches I have done so far either point to
VB scripting/ASP
(http://www.forum4designers.com/archi...-4-209035.html, for
example) or deal with PHP issues that don't seem to address my needs. My
coding knowledge of PHP is non-existent and my html skills are
rudimentary and I don't know anything about how to ping a server. As I
mentioned at the beginning, I'm kind of on my own due to a deadline.


It appears what you may want is requesting a page from the remote
server with a timeout, so if it's down, you find out about it (sorta
quickly). Consider looking at the example code on the stream_set_timeout()
function page on www.php.net, which uses fsockopen() and
stream_set_timeout().

Gordon L. Burditt
Jul 17 '05 #2

P: n/a

"Tim Marshall" <TI****@PurplePandaChasers.Moertherium> wrote in message
news:d3**********@coranto.ucs.mun.ca...
Originally posted with Comp.lang.php spelt stupidly incorrectly. Please
accept my apologies for the resultant multi-post....

Hi, I'm cross posting to comp.infosystems.www.authoring.html and
comp.languages.php. Our IT staff who usually do this sort of thing are
rather busy and I am desperately looking at an impending deadline.

My organization's web page is on a server which has php. A work request
web server is on a separate server which I take down frequently for
maintenance, upgrades and tweaking. What I'm trying to do is create a
page, which will be the link to the work request service, that will
first ping the work request server. If the work request service is
active, it will go to it. If it is down, it will redirect to another page.
Is there anywhere on the web which might have sample code for this sort
of thing? All of the suggestions I have be other knowledgeable
colleagues as well as google searches I have done so far either point to
VB scripting/ASP
(http://www.forum4designers.com/archi...-4-209035.html, for
example) or deal with PHP issues that don't seem to address my needs. My
coding knowledge of PHP is non-existent and my html skills are
rudimentary and I don't know anything about how to ping a server. As I
mentioned at the beginning, I'm kind of on my own due to a deadline.

Thanks very much in advance for any leads on this.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me


In PHP this is super-easy, because HTTP retrieval is an intergral part of
the file-handling mechanism. Something like this will do the job:

<?php

if(fopen("http://www.workrequest.com/", "rb")) {
header("Location: http://www.workrequest.com/");
}
else {
header("Location: /sitedown.php");
}

?>

Jul 17 '05 #3

P: n/a
> Is there anywhere on the web which might have sample code for this sort
of thing? All of the suggestions I have be other knowledgeable


Sample code will be found using PHP's fsockopen function:
http://us4.php.net/fsockopen

Although this is not tested, you could do something like:

<?php
$fp = @fopen("http://www.yahoo.com/NotFound", "r");
if (!$fp) {
// Go Here Instead
header("Location: http://www.example.com/");
exit;
} else {
fclose($fp);
header("Location: http://www.yahoo.com/NotFound");
exit;
}
?>
The above would be it's own php page such as PageFinder.php.
You would link to this php page, and allow it to figure out where to direct
the visitor.
--
-Wil Moore III, MCP
www.digitallysmooth.com
Jul 17 '05 #4

P: n/a
Gordon Burditt wrote:
It appears what you may want is requesting a page from the remote


Will, Chung and Gordan, thanks very much for your prompt replies. I'm
still trying to sort these suggestions, sites and code out, but will
figure this out.

I really appreciate the starting points provided.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.