[PHP] Max.Uptime

Who can give a script for Max Uptime?

Config:

[CODE]<?php

$ip = “”;

$port = “”;

$host = “”;

$user = “”;

$pass = “”;

$characters = “”;

$auth = “”;

$cod = ‘utf8’;

?>[/CODE]

[B]

Uptime Server:[/B]

[CODE]<?php

require_once ( ‘config.php’);

mysql_connect($host, $user, $pass) or die (“Can’t connect with $host”);

mysql_selectdb (“$auth”);

$sql = mysql_query (“SELECT * FROM $auth.uptime ORDER BY starttime DESC LIMIT 1”);

$uptime_results = mysql_fetch_array($sql);

if ($uptime_results[‘uptime’] > 86400) {

$uptime =  round(($uptime_results['uptime'] / 24 / 60 / 60),2)." Days";

}

elseif($uptime_results[‘uptime’] > 3600) {

$uptime =  round(($uptime_results['uptime'] / 60 / 60),2)." Hours";

}

else {

$uptime =  round(($uptime_results['uptime'] / 60),2)." Min";

}

echo “Uptime:$uptime
”;

?>[/CODE]

not correctly plow Uptime: 10 Min

you can use this code too, and any config.php file.


<?php

include "../config.php";

$id = preg_replace( "/[^0-9]/", "", $_GET['id'] ); //only numbers

function test_serv($port){

 global $server;

 $s = @fsockopen($server, $port, $ERROR_NO, $ERROR_STR,(float)0.5);

 if($s){@fclose($s);return true;} else return false;

 }


if (test_serv($realm[$id]['port']))

echo "<span class='colorgood'>Online</span><br>";

else

echo "<span class='colorbad'>Offline</span><br>";


mysql_connect($db_host, $db_user, $db_pass) or die ("Can't connect with host");

mysql_selectdb ("$acc_db");


$sql = mysql_query("SELECT * FROM `uptime` ORDER BY `starttime` DESC LIMIT 0, 1"); 

$row = mysql_fetch_array($sql);    


$day = floor($row['uptime'] / 86400);

$hour = floor($row['uptime'] / 3600) - $day * 24;

$min = floor($row['uptime'] / 60 / 60);

$uptime_string = $day.'d'.$hour.'h'.$min.'m';


echo "<span style= color:#FFF569>Server Uptime: $uptime_string </span><br>";

Server Uptime: 0d0h0m

[CODE]<?php
$host = “”;
$user = “”;
$pass = “”;
$db_base = “auth”;
$uptime = “0”;

$db_link = mysql_connect($host, $user, $pass)
or die(“Couldn’t connect to database server.”);
mysql_select_db($db_base, $db_link)
or die(“Couldn’t select database.”);

$res = mysql_query(“SELECT MAX(starttime) AS begin, uptime
FROM uptime
WHERE realmid = 1
GROUP BY startstring ORDER BY begin DESC LIMIT 0,1”);
if (is_resource($res)) {
$uptime = mysql_result($res, 0, 1);
$sec = $uptime % 60 . “s”;
$min = (intval($uptime / 60)) % 60 . "m ";
$hour = (intval($uptime / 3600)) % 24 . "h ";
$day = intval($uptime / 86400) . "d ";
$uptime = $day.$hour.$min.$sec;
}

echo $uptime;

?>[/php][/CODE]

[CODE]<?php

$uptime = @exec(‘uptime’);

preg_match(“/averages?: ([0-9.]+),[\s]+([0-9.]+),[\s]+([0-9.]+)/”,$uptime,$avgs);

$uptime = explode(’ up ', $uptime);

$uptime = explode(‘,’, $uptime[1]);

$uptime = $uptime[0].', '.$uptime[1];

echo “Server Uptime: “.$uptime.” hours”;

?>[/CODE]

/emoticons/default_biggrin.png

DAS

Don’t mix up wow max uptime with the os current uptime.

here Stas, try this one out for size…

[CODE]<?php

$host = “”;

$user = “”;

$pass = “”;

$auth = “auth”;

mysql_connect($host, $user, $pass) or die (“Can’t connect with $host”);

mysql_select_db (“$auth”);

$result = mysql_query (“SELECT uptime FROM $auth.uptime ORDER BY uptime DESC LIMIT 1”);

$curtime = mysql_result($result,0,0);

$sec = $curtime%(60);

$min = floor(($curtime/60)%60);

$hours = floor(($curtime/(60*60))%24);

$days = floor($curtime/(606024));

$result = mysql_query (“SELECT startstring FROM $auth.uptime ORDER BY uptime DESC LIMIT 1”);

$date = mysql_result ($result,0,0);

echo “Max Time Online: $days days $hours hrs $min min $sec sec
”;

echo “Date and Time of Start: $date
”;[/CODE]

i’ve been useing this code for weeks for my server(i generalized the varibles for you tho)

Nah, don’t trust the uptime field, its updated only every 15 minutes or something.

Instead use the starttime field, and calculate the difference between it and the current time:

SELECT UNIX_TIMESTAMP() - `starttime` `uptime`, `maxplayers` FROM `uptime` ORDER BY `starttime` DESC LIMIT 1

Now you have the uptime time with precision of a second.

Yet it won’t tell you if the server is dead or alive, its actually telling how much time passed sinse the last time the server started. To detect if the server is alive, you can use this function:


    function ping_server($server, $port, $max_ms = 500) {

        @ $fd = fsockopen($server, $port, $errno, $errstr, $max_ms / 1000);

        if ($fd) {

            @ fclose($fd);

            return TRUE;

        }

        return FALSE;

    }

    $server_is_alive = ping_server('127.0.0.1', 8085);

Its a simply attempt to connect to the server. If the connection succeed in less then 500ms returns TRUE meaning the server answered and is alive.

It’s a great plus for web-developing. Information must be cached. There no need to make query with every update of the site by single user.

I will post a new Script for 3 Realms with Uptime, Online and Offline State, Player Online and GM Online.

mfg Soul

[CODE]<?php

echo "<body style=\"background-image:url(images/stats.jpg)\">";

echo "<b><font size=4 color=red><u>Online Status</u></font><br /></b><br/>";

$fp = @fsockopen("localhost",3724,&$errno,&$errstr,2);

if(!$fp)

{

echo "<font color=red size=3><b> Login Offline</b><br><br></font>";

}

else

{

echo '<font size=3 color=green><b> Login Online</b><br></font>';

}

@fclose($fp);

$fp = @fsockopen("localhost",8085,&$errno,&$errstr,2);

if(!$fp)

{

echo "<font color=red size=3><b> Aragon Offline</b><br><br></font>";

}

else

{

echo'<font size=3 color=green><b> Aragon Online</b><br></font>';

}

@fclose($fp);

$fp = @fsockopen("localhost",8086,&$errno,&$errstr,2);

if(!$fp)

{

echo "<font color=red size=3><b> Elusio Offline</b><br><br></font>";

}

else

{

echo'<font size=3 color=green><b> Elusio Online</b><br></font>';

}

@fclose($fp);

$fp = @fsockopen("localhost",8087,&$errno,&$errstr,2);

if(!$fp)

{

echo "<font color=red size=3><b> Embrosia-High Offline</b><br><br></font>";

}

else

{

echo'<font size=3 color=green><b> Embrosia-High Online</b><br></font><br>';

}

@fclose($fp);

$conn = mysql_connect("localhost:3306",sqluser,pw) or die(mysql_error());


mysql_select_db("Realmdb") or die(mysql_error());

$uptime = mysql_query ("select max(`starttime`) from `uptime` WHERE realmid = '1'");

$uptime = time()-mysql_result ($uptime,0);

$uptime = intval ($uptime/60);

$min = $uptime%60;

$uptime = intval ($uptime/60);

$hours = $uptime%24;

$uptime = intval($uptime/24);

$days = $uptime;

$max = mysql_query ("select max(`maxplayers`) from `uptime` WHERE `realmid` = '1'");     

$max = mysql_result ($max,0);


   echo '<font color=red> ______________________<br>';

echo'<font color=red> Aragon Online Seit:<br></font>';

echo '<font color="red">'.floor ($days)."<font size=2 color=red> Tagen </font><font color=red>".floor ($hours)."<font size=2 color=red> Std </font><font color=red>".($min)."<font size=2 color=red> Min </font><br><br>";


mysql_select_db("Char DB") or die(mysql_error());

$result = mysql_query ("SELECT count(*) FROM characters WHERE online = 1 AND account IN (SELECT id FROM Login.account WHERE gmlevel >0)");

$row = mysql_fetch_array($result,MYSQL_NUM);

$onlinehorde_querry = "SELECT count(*) as count FROM `characters` WHERE `race` in (2,5,6,8,10) AND `online`='1'";

$onlinehorde_result = mysql_query($onlinehorde_querry);

$onlinehorde = mysql_fetch_object($onlinehorde_result)->count;

$onlineally_querry = "SELECT count(*) as count FROM `characters` WHERE `race` in (1,3,4,7,11) AND `online`='1'";

$onlineally_result = mysql_query($onlineally_querry);

$onlineally = mysql_fetch_object($onlineally_result)->count;

$onlineall = $onlineally + $onlinehorde;




echo '<font color=red> Horde : ' . $onlinehorde . '<br>';

echo '<font color=red> Allianz : ' . $onlineally . '<br>';

echo '<font color=red> Spieler : ' . $onlineall . '<br>';

echo '<font color=red> Max online: ' . $max . '<br>';

echo '<font color=red> GMs online: ' .$row[0] . '<br>';

echo '<font color=red> ______________________<br>';

mysql_close($conn);

$conn = mysql_connect("localhost:3306",DBUser,pw) or die(mysql_error());


mysql_select_db("Login") or die(mysql_error());


$uptime = mysql_query ("select max(`starttime`) from `uptime` WHERE realmid = '2'");

$uptime = time()-mysql_result ($uptime,0);

$uptime = intval ($uptime/60);

$min = $uptime%60;

$uptime = intval ($uptime/60);

$hours = $uptime%24;

$uptime = intval($uptime/24);

$days = $uptime;

$maxi = mysql_query ("select max(`maxplayers`) from `uptime` WHERE realmid = '2'");     

$maxi = mysql_result ($maxi,0);

echo'<font color=red> Elusio Online Seit:<br></font>';

echo '<font color="red">'.floor ($days)."<font size=2 color=red> Tagen </font><font color=red>".floor ($hours)."<font size=2 color=red> Std </font><font color=red>".($min)."<font size=2 color=red> Min </font><br><br>";


mysql_select_db("PvE_Chars") or die(mysql_error());

$result = mysql_query ("SELECT count(*) FROM characters WHERE online = 1 AND account IN (SELECT id FROM Login.account WHERE gmlevel >0)");

$row = mysql_fetch_array($result,MYSQL_NUM);

$onlinehorde_querry = "SELECT count(*) as count FROM `characters` WHERE `race` in (2,5,6,8,10) AND `online`='1'";

$onlinehorde_result = mysql_query($onlinehorde_querry);

$onlinehorde = mysql_fetch_object($onlinehorde_result)->count;

$onlineally_querry = "SELECT count(*) as count FROM `characters` WHERE `race` in (1,3,4,7,11) AND `online`='1'";

$onlineally_result = mysql_query($onlineally_querry);

$onlineally = mysql_fetch_object($onlineally_result)->count;

$onlineall = $onlineally + $onlinehorde;



echo '<font color=red> Horde : ' . $onlinehorde . '<br>';

echo '<font color=red> Allianz : ' . $onlineally . '<br>';

echo '<font color=red> Spieler : ' . $onlineall . '<br>';

echo '<font color=red> Max online: ' . $maxi . '<br>';

echo '<font color=red> GMs online: ' .$row[0] . '<br>';

echo '<font color=red> ______________________<br>';

mysql_close($conn);

$conn = mysql_connect("localhost:3306",DBUser,pw) or die(mysql_error());


mysql_select_db("Login") or die(mysql_error());

$uptime = mysql_query ("select max(`starttime`) from `uptime` WHERE realmid = '3'");

$uptime = time()-mysql_result ($uptime,0);

$uptime = intval ($uptime/60);

$min = $uptime%60;

$uptime = intval ($uptime/60);

$hours = $uptime%24;

$uptime = intval($uptime/24);

$days = $uptime;

$max = mysql_query ("select max(`maxplayers`) from `uptime` WHERE `realmid` = '3'");     

$max = mysql_result ($max,0);


echo'<font color=red> Embrosia-High Online Seit:<br></font>';

echo '<font color="red">'.floor ($days)."<font size=2 color=red> Tagen </font><font color=red>".floor ($hours)."<font size=2 color=red> Std </font><font color=red>".($min)."<font size=2 color=red> Min </font><br><br>";


mysql_select_db("Fun_Chars") or die(mysql_error());

$result = mysql_query ("SELECT count(*) FROM characters WHERE online = 1 AND account IN (SELECT id FROM Login.account WHERE gmlevel >0)");

$row = mysql_fetch_array($result,MYSQL_NUM);

$onlinehorde_querry = "SELECT count(*) as count FROM `characters` WHERE `race` in (2,5,6,8,10) AND `online`='1'";

$onlinehorde_result = mysql_query($onlinehorde_querry);

$onlinehorde = mysql_fetch_object($onlinehorde_result)->count;

$onlineally_querry = "SELECT count(*) as count FROM `characters` WHERE `race` in (1,3,4,7,11) AND `online`='1'";

$onlineally_result = mysql_query($onlineally_querry);

$onlineally = mysql_fetch_object($onlineally_result)->count;

$onlineall = $onlineally + $onlinehorde;




echo '<font color=red> Horde : ' . $onlinehorde . '<br>';

echo '<font color=red> Allianz : ' . $onlineally . '<br>';

echo '<font color=red> Spieler : ' . $onlineall . '<br>';

echo '<font color=red> Max online: ' . $max . '<br>';

echo '<font color=red> GMs online: ' .$row[0] . '<br>';

echo '<font color=red> ______________________<br>';

mysql_close($conn);

?>[/CODE]

and config to script

[CODE]<?php

$ip = “ip”;

$port = “8085”;

$host = “zrl oder ip”;

$user = “Mysql user”;

$pass = “pw”;

$mangoscharacters = “Char_DB”;

$mangosrealm = “Login DB”;

$cod = ‘utf8’;

?>[/CODE]

for every Realm you have to make own config like config.php,config1.php,config2.php so i made that.

Much Fun whith the Script

Would be easier to make a table for realms, and make the script query per realm in table instead of adding a config per realm…

Its a bit messy, but all I do is:


//Realms Function

function realm(){

include("./core/core_includes/config.php");

$get_realms = mysql_query("SELECT * FROM $db_site.realms");

while ($got_realms = mysql_fetch_array($get_realms)){

$realm = array(

"id" => $got_realms['id'],

"name" => $got_realms['name'], 

"port" => $got_realms['port'],

"db" => $got_realms['db'],

"type" => $got_realms['type']

);

$err = array('no' => NULL, 'str' => NULL);

$arcemu = @fsockopen($db_host, $realm[port], $err['no'], $err['str'], (float)1.0);

		if(!$arcemu){

			$world = "Offline - ";

		}else{

			$world = "Online - ";

		}

		fclose($arcemu);

print'<div style="margin-left:10px;">'.$world.'<a href="./page.php?page=realm_status&id='.$realm[id].'">'.$realm[name].'</a> | '.$realm[type].'</div>';

}}

//End Realms

originally coded for ArcEmu, but works for Trinity too… thats why my variable is $arcemu.

Just add the max uptime to it…