Get server status with PHP or Javascript? -


i have been trying working server status script work without success. there's community runs 1 themself looks cool , wondering if me out?

https://lemonpunch.net/servers/

i've looked on stackoverflow website seems of them doesn't work.

my current code:

<!doctype html> <html> <head> <title>server status</title> <link type="text/css" rel="stylesheet" href="assets/styles/odometer-theme-default.css"/> <link type="text/css" rel="stylesheet" href="assets/styles/app.css"/> <script type="text/javascript">             var initial = true;             var servers = [];                              servers.push({                     id: 1,                     status: "down",                     loaded: false,                     maxplayers: 0,                     playerlist: []                 });                             servers.push({                     id: 2,                     status: "down",                     loaded: false,                     maxplayers: 0,                     playerlist: []                 });                             servers.push({                     id: 4,                     status: "down",                     loaded: false,                     maxplayers: 0,                     playerlist: []                 });                     </script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> <script type="text/javascript" src="assets/javascript/odometer.min.js"></script> <script type="text/javascript" src="assets/javascript/app.js"></script> </head> <body> <div class="wrapper"> <div class="box big"> <a href="https://solitynetwork.net/"><img src="/images/logo444x98_87eed8146e1c8ec38f8c37402e74409c.png" alt="solity network"/></a> <h1><span class="playercount current odometer">0</span>/<span class="playercount max odometer">0</span> players online right now</h1> </div> <div class="loadbar"></div> <div class="box server" data-serverid="1"> <h1>half-life 2 roleplay: city</h1> <div class="status"> <div class="count odometer">0</div> <div class="loader"></div> </div> <div class="clear"></div> </div> <div class="box info" data-serverid="1"> <ul></ul> </div> <div class="box server" data-serverid="2"> <h1>half-life 2 roleplay: outlands</h1> <div class="status"> <div class="count odometer">0</div> <div class="loader"></div> </div> <div class="clear"></div> </div> <div class="box info" data-serverid="2"> <ul></ul> </div> <div class="box server" data-serverid="4"> <h1>world war 3 roleplay</h1> <div class="status"> <div class="count odometer">0</div> <div class="loader"></div> </div> <div class="clear"></div> </div> <div class="box info" data-serverid="4"> <ul></ul> </div> </div> </body> </html> 

with php, use shell_exec command ping specific ip , determine if it's online. if backend run on linux, should work:

$offline = shell_exec("ping -c 1 8.8.8.8 | grep -c '0 received'");

the above return 1 if offline, or if first packet lost, , 0 if online or first packet received. not account packetloss.

another alternative sign actual reliable , redundant service monitoring, has api, , fetch status via site. depending on actual needs, may prove far more reliable.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -