SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru kgtrip's Avatar
    Join Date
    Jun 2003
    Location
    Karplakistan
    Posts
    804
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    detecting server is down & redirect?

    Hi folks,

    I was wondering, is there a way in php to detect if the server is down and if so, to redirect to another server?
    Compare Hundreds of Web Hosting Plans

  2. #2
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could take your question two ways, not sure what you are asking though...

    1) if someone is going to your site, will your PHP be able to redirect them to another site? Well, there's not much PHP will be able to do for you... if the server is down, the request sure isn't getting to the PHP code. Try searching the net for "Fault Tolerance", or "High-Availability" server configurations... basically a cluster (two or more servers) that are specifically configured to provide redundancy if the other one(s) go down or become temporarily unavailable. I believe "load balancing" may achieve the same result as well.

    --- OR ---

    2) if I have a link on my site to another site, can I tell whether or not it is down via PHP and if it is display another link that is up? You can probably try to fetch something from that site, like
    PHP Code:
    $lines file('http://www.example.com/'); 
    If something is returned than it's fairly safe to say that the site is up; else display another link.

  3. #3
    SitePoint Guru kgtrip's Avatar
    Join Date
    Jun 2003
    Location
    Karplakistan
    Posts
    804
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by trogdor1024
    I could take your question two ways, not sure what you are asking though...

    1) if someone is going to your site, will your PHP be able to redirect them to another site? Well, there's not much PHP will be able to do for you... if the server is down, the request sure isn't getting to the PHP code. Try searching the net for "Fault Tolerance", or "High-Availability" server configurations... basically a cluster (two or more servers) that are specifically configured to provide redundancy if the other one(s) go down or become temporarily unavailable. I believe "load balancing" may achieve the same result as well.

    --- OR ---

    2) if I have a link on my site to another site, can I tell whether or not it is down via PHP and if it is display another link that is up? You can probably try to fetch something from that site, like
    PHP Code:
    $lines file('http://www.example.com/'); 
    If something is returned than it's fairly safe to say that the site is up; else display another link.
    OK thanks trogdor1024,

    I was just looking for a way to stay "online" even if the server is down. I guess the question should be directed to my web hosting company. I would need 2 different servers for this. Thanks again...
    Compare Hundreds of Web Hosting Plans

  4. #4
    Woof! Woof! elel1138's Avatar
    Join Date
    Apr 2004
    Location
    Warsaw, Poland
    Posts
    202
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This can be done, however you will need _three_ computers . Two (or maybe more) of them doing the actual job, and one of them acting as a reverse proxy, ie. checking if the servers are up and redirecting the user accordingly.

    I guess it isn't very useful in normal use. However, this can be useful if you need load balancing...
    Leszek Leszczyński
    www.hazelsoft.com
    --- Real programmers don't document. If it was hard to write,
    it should be hard to understand. ---


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •