Jump to content

Forums Announcement

Read-Only Mode for Announcements & Changelogs

Dear Survivors, we'd like to inform you that this forum will transition to read-only mode. From now on, it will serve exclusively as a platform for official announcements and changelogs.

For all community discussions, debates, and engagement, we encourage you to join us on our social media platforms: Discord, Twitter/X, Facebook.

Thank you for being a valued part of our community. We look forward to connecting with you on our other channels!

Stay safe out there,
Your DayZ Team

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
Sign in to follow this  

×