Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Server Status Online/Offline

  1. #1
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Server Status Online/Offline

    Tried several more methods they all for me.. don't work.


    For example the one below says it's offline

    Code:
    <?php
    
    $server_host = "http://www.google.com";
    $server_port = 80;
    
    $conn = @fsockopen($server_host, $server_port, $errno, $err_string, 10);
    if($conn === false) {
          // server is offline
    echo 'Server appears to be offline';
    }
    else {
          // server is online
    echo 'Server Online';
    }
    
    ?>
    Last edited by YourGreatestMember; 12-20-2008 at 06:02 PM.

  2. #2
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Still can't get it going...

    EDIT: Where's my original post gone??

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    This worked for me...
    PHP Code:
        <?php

    $conn 
    fsockopen("www.google.com"80$errno$errstr30);
    if(
    $conn === false) {
          
    // server is offline
    echo 'Server appears to be offline';
    }
    else {
          
    // server is online
    echo 'Server Online';
    }

    ?>

  4. #4
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    What hosting company are you using?

    Some host do not allow things like this....

  5. #5
    Join Date
    Dec 2008
    Location
    Nigeria
    Posts
    95
    Thanks
    3
    Thanked 8 Times in 8 Posts

    Default

    Try this one:
    <?php
    ###local server_name => 127.0.0.1,localhost or computername
    function sonline() {if ($_SERVER['SERVER_NAME']=="localhost"||$_SERVER['SERVER_NAME']=="127.0.0.1"||strtolower($_SERVER['SERVER_NAME'])==strtolower(getenv('COMPUTERNAME'))) {return false;} else {return true;}}

    if(sonline()) {echo "Hooray, i am online, its xmas!";} else {echo "No way, i'm offline and it's boxing day already!";}
    ?>

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    That only works for the local server, I think the OP is trying to see the status of remote servers. The code that bluewalrus posted should work; however, benslayton is also correct due to the fact that it depends on the settings of the hosting server. They may or may not allow doing this.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The only way around it if you can't use something like that would be to get a remote file another way and see if it loaded, like an image. If you can't even work that out (due to restrictions on remote urls), then you could even do it using Javascript, just by loading an image (a very small test, maybe 10x10px, or even just 1x1), then if that works go ahead and if not loop through the next servers until one does work.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Dec 2008
    Location
    Nigeria
    Posts
    95
    Thanks
    3
    Thanked 8 Times in 8 Posts

    Default

    You can use an ajax http post request, look at the return status code, 401,404.....to determine if the server is available, that should do it.

  9. #9
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by diltony View Post
    You can use an ajax http post request, look at the return status code, 401,404.....to determine if the server is available, that should do it.
    I was going to suggest the same thing. It's actually quite simple. I ran across this page a few days ago (via Subtraction.com). It uses a similar technique to check if a particular username is available at various sites.

  10. #10
    Join Date
    Dec 2008
    Location
    Nigeria
    Posts
    95
    Thanks
    3
    Thanked 8 Times in 8 Posts

    Default

    I tried the direct ajax method, failed cos i forgot to that ajax cannot cross domains directly, so i had to add a few lines of php code.
    i posted the solution on http://www.dynamicdrive.com/forums/s...ad.php?t=40179
    the main engine is the php script, as usual i added an ajax interface to it.

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
  •