[Share]Advanced Php Server Status L2J 

Status
Not open for further replies.
Newbie Spellweaver
Joined
Dec 24, 2006
Messages
71
Reaction score
37
I wasn't gonna release it at first. But what the heck, here you go guys. A advanced php server status coded by me. Use it if you know php, I won't make a 'stupid guide' if something goes wrong or you want to change it. Tells you if the server is offline or not and if its lagging or not. I would advise changing ping values cause a server pinging a server will have a good connection, so try evening it out, for people using it localhost. It will always say great, so....yea. HF
xsilentx - [Share]Advanced Php Server Status - RaGEZONE Forums

Code:
<?php

$server = "localhost";
$port = "2106";

function pingDomain($server){
    $starttime = microtime(true);//Server 1 Port
    $file      = fsockopen ($domain, 2106, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 1000;
        $status = floor($status);
    }
    return $status;
}      

        $status = pingDomain($serverbase);
        if ($status <= 50) $MessageStatus = "Great";
        elseif ($status <= 80) $MessageStatus = "Good";
        elseif ($status <= 100) $MessageStatus = "Ok";
        elseif ($status <= 150) $MessageStatus = "Bad";
        elseif ($status <= 999) $MessageStatus = "Poor";
        else $MessageStatus = "Disconnected";


$upmessage = "<font size='1' color='white'><br>Stability: </font><font color='gray' 

size='1'>$MessageStatus</font><br>";
$downmessage = "<font size='1' color='white'><br>Stability: </font><font color='gray' 

size='1'>Disconnected</font><br>";
$tout = "5";
$server1 = @fsockopen ($server, $port, $errno, $errstr, $tout);
if(!$server1){ echo"<br><font color='C8B560' size='2' style='Arial'><strong>Login</strong></font><br><font 

size='1' color='white'>Status:</font><font color='red' size='1' style='Arial'> Off</font>$downmessage"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Login</strong></font><br><font size='1' 

color='white'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage"; }

$server2 = "localhost";
$port2 = "7777";

function pingDomain2($server2){
    $starttime2 = microtime(true);//Server 2 Port
    $file2      = fsockopen ($domain2, 7777, $errno, $errstr, 10);
    $stoptime2  = microtime(true);
    $status2    = 0;

    if (!$file2) $status2 = -1;
    else {
        fclose($file2);
        $status2 = ($stoptime2 - $starttime2) * 1000;
        $status2 = floor($status2);
    }
}      

        $status2 = pingDomain2($serverbase2);
        if ($status2 <= 50) $MessageStatus2 = "Great";
        elseif ($status2 <= 80) $MessageStatus2 = "Good";
        elseif ($status2 <= 100) $MessageStatus2 = "Ok";
        elseif ($status2 <= 150) $MessageStatus2 = "Bad";
        elseif ($status2 <= 999) $MessageStatus2 = "Poor";
        else $MessageStatus2 = "Disconnected";


$upmessage2 = "<font size='1' color='white'><br>Stability: </font><font color='gray' 

size='1'>$MessageStatus2</font><br>";
$downmessage2 = "<font size='1' color='white'><br>Stability: </font><font color='gray' 

size='1'>Disconnected</font><br>";
$tout = "5";
$server2 = @fsockopen ($server2, $port2, $errno, $errstr, $tout);
if(!$server2){ echo"<br><font color='C8B560' size='2' 

style='Arial'><strong>Gameserver</strong></font><br><font size='1' color='white'>Status:</font><font 

color='red' size='1' style='Arial'> Off</font>$downmessage2"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Gameserver</strong></font><br><font 

size='1' color='white'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage2"; }
?>
 
I wasn't gonna release it at first. But what the heck, here you go guys. A advanced php server status coded by me. Use it if you know php, I won't make a 'stupid guide' if something goes wrong or you want to change it. Tells you if the server is offline or not and if its lagging or not. I would advise changing ping values cause a server pinging a server will have a good connection, so try evening it out, for people using it localhost. It will always say great, so....yea. HF
xsilentx - [Share]Advanced Php Server Status - RaGEZONE Forums

Code:
<?php

$server = "localhost";
$port = "2106";

function pingDomain($server){
    $starttime = microtime(true);//Server 1 Port
    $file      = fsockopen ($domain, 2106, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 1000;
        $status = floor($status);
    }
    return $status;
}      

        $status = pingDomain($serverbase);
        if ($status <= 50) $MessageStatus = "Great";
        elseif ($status <= 80) $MessageStatus = "Good";
        elseif ($status <= 100) $MessageStatus = "Ok";
        elseif ($status <= 150) $MessageStatus = "Bad";
        elseif ($status <= 999) $MessageStatus = "Poor";
        else $MessageStatus = "Disconnected";


$upmessage = "<font size='1' color='white'><br>Stability: </font><font color='gray' 

size='1'>$MessageStatus</font><br>";
$downmessage = "<font size='1' color='white'><br>Stability: </font><font color='gray' 

size='1'>Disconnected</font><br>";
$tout = "5";
$server1 = @fsockopen ($server, $port, $errno, $errstr, $tout);
if(!$server1){ echo"<br><font color='C8B560' size='2' style='Arial'><strong>Login</strong></font><br><font 

size='1' color='white'>Status:</font><font color='red' size='1' style='Arial'> Off</font>$downmessage"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Login</strong></font><br><font size='1' 

color='white'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage"; }

$server2 = "localhost";
$port2 = "7777";

function pingDomain2($server2){
    $starttime2 = microtime(true);//Server 2 Port
    $file2      = fsockopen ($domain2, 7777, $errno, $errstr, 10);
    $stoptime2  = microtime(true);
    $status2    = 0;

    if (!$file2) $status2 = -1;
    else {
        fclose($file2);
        $status2 = ($stoptime2 - $starttime2) * 1000;
        $status2 = floor($status2);
    }
}      

        $status2 = pingDomain2($serverbase2);
        if ($status2 <= 50) $MessageStatus2 = "Great";
        elseif ($status2 <= 80) $MessageStatus2 = "Good";
        elseif ($status2 <= 100) $MessageStatus2 = "Ok";
        elseif ($status2 <= 150) $MessageStatus2 = "Bad";
        elseif ($status2 <= 999) $MessageStatus2 = "Poor";
        else $MessageStatus2 = "Disconnected";


$upmessage2 = "<font size='1' color='white'><br>Stability: </font><font color='gray' 

size='1'>$MessageStatus2</font><br>";
$downmessage2 = "<font size='1' color='white'><br>Stability: </font><font color='gray' 

size='1'>Disconnected</font><br>";
$tout = "5";
$server2 = @fsockopen ($server2, $port2, $errno, $errstr, $tout);
if(!$server2){ echo"<br><font color='C8B560' size='2' 

style='Arial'><strong>Gameserver</strong></font><br><font size='1' color='white'>Status:</font><font 

color='red' size='1' style='Arial'> Off</font>$downmessage2"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Gameserver</strong></font><br><font 

size='1' color='white'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage2"; }
?>

Nice work but it is better to put :
Code:
 function pingDomain($server){
    $starttime = microtime(true);//Server 1 Port
    $file      = [COLOR=Red]@[/COLOR]fsockopen ($domain, $port, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;
you have to put there @ for covering those error messages if the server is down or not responding.
 
Nice share. Thank you. Colors sad but that can be fixed.
 
Nice work but it is better to put :
Code:
 function pingDomain($server){
    $starttime = microtime(true);//Server 1 Port
    $file      = [COLOR=Red]@[/COLOR]fsockopen ($domain, $port, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;
you have to put there @ for covering those error messages if the server is down or not responding.

Thanks for fix, but when the Game and Login servers are offline than is showing only Login server status.
 
Thanks for fix, but when the Game and Login servers are offline than is showing only Login server status.
PHP:
function pingDomain2($server2){
    $starttime2 = microtime(true);//Server 2 Port
    $file2      = @fsockopen ($domain2, 7777, $errno, $errstr, 3);
    $stoptime2  = microtime(true);
    $status2    = 0;
    if (!$file2) $status2 = -1;
    else {
        fclose($file2);
        $status2 = ($stoptime2 - $starttime2) * 1000;
        $status2 = floor($status2);
    }
}

bcuz you have to change the 2nd ping domain function also just add @ to fsockopen.

PS.: this script could be writen much easier, but it's not my script :)
 
I have problem with this script. It is showing me real status only sometimes (approx. 1 of 10 reloads). So what i did wrong ? script is on paid webhost while server machine is in my home & running. All ports supposed to be opened as it is sometimes showing status online, but really only sometimes.
 
Maby your server is too tight on flooding that port. So make a time delay to it so that your server doesn't put it to the flood list.
 
Status
Not open for further replies.
Back