www.webdeveloper.com
Results 1 to 14 of 14

Thread: Online or Offline?

  1. #1
    Join Date
    Feb 2003
    Posts
    8

    Unhappy Online or Offline?

    Is there a way in php to tell a user if a mirror is online or offline without me changing it? I also want to know if there is a way to automatically redirect to the one(or either one) that is online? Here is an example of a page I have found that has/does this: http://home.hccnet.nl/h.edskes/mirror.htm

    Thanks.

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    You should probably use CGI to Ping the server. That is the best way. PHP doesn't have a Ping function, so this can only be done in CGI.

  3. #3
    Join Date
    Feb 2003
    Posts
    8
    Well do you know the code for the CGI one?

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Sure don't. Try the CGI forum.

  5. #5
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    Actually you can ping in PHP (although strictly it isn't PHP...)

    PHP Code:
    $host="www.yoursite.com";
    $ping=system("ping $host");
    echo 
    $ping
    That should do the trick, although the results won't be brilliantly formatted.

  6. #6
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    If it's not strictly PHP, then what is it?
    Last edited by Jona; 05-26-2003 at 05:53 PM.

  7. #7
    Join Date
    Dec 2002
    Location
    WI, United States
    Posts
    1,372
    I would suggest that you use this instead:
    PHP Code:
    <?PHP
    $file 
    "http://www.yourdomain.com/index.htm";
    $fp = @file($file);
    if(
    $fp){
        echo 
    "server up!";
    }else{
        echo 
    "server down!";
    }
    ?>
    Change the $file to be a file that is on your server. Then it will tell you if the server that the file is on is up or down. Cijori's method would be fine, but it won't work on all servers...

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You also don't need to use a ping (although that is the best way). You could simply try to open a file on the server and detect whether or not it opened or not... Something like:

    PHP Code:
    $file "http://www.youdomain.com/online.txt"//set this to some page that you know is on your server
    $online = @file($file);
    if (
    $online) {
        
    #page is online
    }
    else {
        
    #page is offline


  9. #9
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    AdamBrill posted while I was typing up a reply...

  10. #10
    Join Date
    Feb 2003
    Posts
    8
    Thanks guys. I will try it to see if it works.

  11. #11
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    Originally posted by Jona
    If it's not strictly PHP, then what is it?
    It is actually running the ping program which is present on about 99% of servers via PHP.

  12. #12
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    I have the Ping program in my WINDOWS folder of my computer. Could I upload that and edit my Apache handlers to run the program when PHP executes it with the system() command? Or would I just have to install C or something?

  13. #13
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    I don't know - have you tried running ping without changing anything?

  14. #14
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Yes, I tested your original code and my result was a completely, 100% blank page.

    Jona

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles