Ping A Page, Reddirect if Not Available

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Marshall

    #1

    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.infosystem s.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
  • Gordon Burditt

    #2
    Re: Ping A Page, Reddirect if Not Available

    >My organization's web page is on a server which has php. A work request[color=blue]
    >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.[/color]

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

    [color=blue]
    >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.[/color]

    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_time out()
    function page on www.php.net, which uses fsockopen() and
    stream_set_time out().

    Gordon L. Burditt

    Comment

    • Chung Leong

      #3
      Re: Ping A Page, Reddirect if Not Available


      "Tim Marshall" <TIMMY!@PurpleP andaChasers.Moe rtherium> wrote in message
      news:d3m512$695 $1@coranto.ucs. mun.ca...[color=blue]
      > 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.infosystem s.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[/color]
      page.[color=blue]
      >
      > 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[/color]

      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("Locatio n: http://www.workrequest .com/");
      }
      else {
      header("Locatio n: /sitedown.php");
      }

      ?>



      Comment

      • Guest's Avatar

        #4
        Re: Ping A Page, Reddirect if Not Available

        > Is there anywhere on the web which might have sample code for this sort[color=blue]
        > of thing? All of the suggestions I have be other knowledgeable[/color]

        Sample code will be found using PHP's fsockopen function:


        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("Locatio n: http://www.example.com/");
        exit;
        } else {
        fclose($fp);
        header("Locatio n: 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



        Comment

        • Tim Marshall

          #5
          Re: Ping A Page, Reddirect if Not Available

          Gordon Burditt wrote:
          [color=blue]
          > It appears what you may want is requesting a page from the remote[/color]

          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

          Comment

          Working...