Ping A Page, Reddirect if Not Available

This is a discussion on Ping A Page, Reddirect if Not Available within the PHP Language forums, part of the PHP Programming Forums category; Originally posted with Comp.lang.php spelt stupidly incorrectly. Please accept my apologies for the resultant multi-post.... Hi, I'...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-14-2005
Tim Marshall
 
Posts: n/a
Default Ping A Page, Reddirect if Not Available

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
Reply With Quote
  #2 (permalink)  
Old 04-14-2005
Gordon Burditt
 
Posts: n/a
Default Re: Ping A Page, Reddirect if Not Available

>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
Reply With Quote
  #3 (permalink)  
Old 04-15-2005
Chung Leong
 
Posts: n/a
Default Re: Ping A Page, Reddirect if Not Available


"Tim Marshall" <TIMMY!@PurplePandaChasers.Moertherium> wrote in message
news:d3m512$695$1@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");
}

?>



Reply With Quote
  #4 (permalink)  
Old 04-15-2005
 
Posts: n/a
Default Re: Ping A Page, Reddirect if Not Available

> 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


Reply With Quote
  #5 (permalink)  
Old 04-18-2005
Tim Marshall
 
Posts: n/a
Default Re: Ping A Page, Reddirect if Not Available

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:04 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0