Jump to content
Sign in to follow this  
ozzybwild

Checking server status via fsockopen

Recommended Posts

Hi everyone!

I hope I found the right place to ask about this..

The problem I have is, that I want to check whether our servers are running or not (like all those serverlisting-services do).

My attempt is to check via fsockopen and thereby ping the ip and the port the server(s) run(s) on.


<?php
//Pingcall:
function ping($host,$port,$timeout=10)
{
$fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
if ( ! $fsock )
{
echo "! ".$errno." ".$errstr." !";
return FALSE;
}
else
{
return TRUE;
}
}
//Listeneintrag, functioncall und Darstellung:
function checkserver($name,$host,$port)
{
$up = ping($host,$port);
echo $name.": ".$host.":".$port." - ";
// online
if( $up )
{
echo "<img src=\"on.png\" alt=\"Server online!\"><br>--------------------------------------<br>";
}
// offline
else
{
echo "<img src=\"off.png\" alt=\"Server offline!\"><br>--------------------------------------<br>";
}
}
//HTML-Header, meta-refresh
echo "<HTML><HEAD><TITLE>Serverstatus</TITLE><META http-equiv=\"refresh\" content=\"150; URL=status.php\"></HEAD><BODY bgcolor=\"black\" TEXT=\"white\">";
//Serverliste:
checkserver('SERVERNAMEHERE',"IPHERE","PORTHERE");
//HTML-Footer
echo "<br><br>©2012: ozzybwild</P></BODY></HTML>";
?>

"SERVERNAMEHERE", "IPHERE" and "PORTHERE" hold a name to display, the IP to be pinged and the port to access.

However it works with none of the DayZ servers I am checking. Pinging my linux root at port 80 however works like a charm, no matter whether I ping the IP itself or the TLD..

Does anyone have an idea how I can check if the serverside application (/DayZ Server) is running or not?

Share this post


Link to post
Share on other sites

You can't really ping an application running on a port, pinging something generally means ICMP

For one thing, arma 2 runs on UDP - so you need to change your host to udp://ip.goes.here - just seeing if the port can be connected to doesn't really mean the server is online. We use the GameQ PHP library to query our game servers from PHP, I would recommend that instead of your method.

  • Like 1

Share this post


Link to post
Share on other sites

Ace!

Took some time to figure out filterung the results properly ( //Use Magic is the most WTF comment I ever read in a source.. :D ), but GameQ is excellent for the job.

Thanks a lot, you got my beans! :)

Share this post


Link to post
Share on other sites

Ich find es lustig wie du in deiner Script Beschreibung Deutsch und Englisch nutzt :D

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×