Follow us on twitter

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthoriGotSkill
    • CommentTimeDec 7th 2009
     
    I'm going to make a CS 1.6 server with my friend. Any way to ping it and see if it's online at the time with PHP so I can display the online / offline stats on my clan's website? don't need other details (such as map, players etc) but would be appreciated.
    • CommentAuthoriGotSkill
    • CommentTimeDec 7th 2009
     
    Code:
    http://www.phptoys.com/e107_plugins/content/content.php?content.41
  1.  
    Code:
    <?php
    $host =  [i]"YOUR IP ADDRESS"[/i];
    $i = "27015";
    $fp = fsockopen($host,$i,$errno,$errstr,10);
    if($fp){$portresult =  "Open"; close($fp);   }
    else{   $portresult =  "Closed";}
    flush();
    echo $portresult;
    ?>

    untested
    • CommentAuthorjuanri
    • CommentTimeDec 7th 2009
     
    Connecting a socket to its rcon port won't tell you for sure. Often servers running in a crashed state keep the port open.
  2.  
    I tried with a random server which is on 27015:
    Code:
    <?php
    $host = "113.212.97.203";
    $i = "27015";
    $fp = fsockopen($host,$i,$errno,$errstr,10);
    if($fp){$portresult =  "Open"; close($fp);   }
    else{   $portresult =  "Closed";}
    flush();
    echo $portresult;
    ?>

    Result:
    Code:
    Warning: fsockopen() [function.fsockopen]: unable to connect to 113.212.97.203:27015 in /home/content/****.php on line 4
    Closed


    The server was up at the time.
    • CommentAuthorkurdboy
    • CommentTimeDec 7th 2009
     
    Darkimmortal is correct. Do you have SSH access to the target server where you can have a cron task simply check the PID and make sure it's running. Not sure if there's an HTTP service installed on that server, if not you can have this cron simply wget a file and the file it grabs could update the status via mysql that you can then display on the site.

    If you want to do it with sockets, this should work:
    Code:
    $host = "113.212.97.203";
    $port = "27015";
    $connection = @fsockopen("udp://".$host, $port, $errno, $errstr, 5);
    echo $connection;
    echo ($connection ? 'Online' : 'Offline');
    ($connection ? fclose($connection) : null);
    • CommentAuthorarshdeep79
    • CommentTimeDec 7th 2009 edited
     

     

    I tried with a random server which is on 27015:
    Code:
    <?php
    $host = "113.212.97.203";
    $i = "27015";
    $fp = fsockopen($host,$i,$errno,$errstr,10);
    if($fp){$portresult =� "Open"; close($fp);� �}
    else{� �$portresult =� "Closed";}
    flush();
    echo $portresult;
    ?>

    Result:
    Code:
    Warning: fsockopen() [function.fsockopen]: unable to connect to 113.212.97.203:27015 in /home/content/****.php on line 4
    Closed


    The server was up at the time.

     



    was that port open though?
    am just testing this now.....

  3.  
    Code:
    <?php

    $connection = @fsockopen('google.co.uk', 80, $errno, $errstr, 5);
    echo ($connection ? 'online' : 'offline');
    ($connection ? fclose($connection) : null);

    ?>


    works
    • CommentAuthorNux2Lux
    • CommentTimeDec 7th 2009
     
    What about this?
    Code:
    http://www.canyouseeme.org/
  4.  

     

    What about this?
    Code:
    http://www.canyouseeme.org/

     



    that only works from the server computer via a browser so it's not possible for me. the server is CS only - no HTTP on that machine.