[PHP]Silkroad server status script

05/05/2012 12:11 SniuurksT#1
Add this script to you functions file or somewhere where it includes.
If you want to print the status use this code:

PHP Code:
echo server_status($ip$port); 
PHP Code:
    //Server status script by: SniuurksT
    
$ip '127.0.0.1'//Server ip adress
    
$port '15779'//Server port
    
    
function server_status($ip$port)
    {
    
$status = array("<strong>Server is:</strong><span style='color:#F00;'>Offline</span>""<strong>Server is:</strong><span style='color:#0F0;'>Online </span>
"
);
    
$fp = @fsockopen($ip$port$errno$errstr2);
    if (!
$fp) {
        return 
$status[0];
    } 
    else
      
      { 
      return 
$status[1];
      }
    } 
05/05/2012 14:00 ermvrs#2
already released
05/07/2012 15:25 SniuurksT#3
ermvrs,
Got many orders to make this simple script, so i just shared it.
07/31/2012 00:10 cjmwid#4
Can you make it so it will show the Max Client's and the current clients along with like refresh??
07/31/2012 20:46 PortalDark#5
Quote:
Originally Posted by cjmwid View Post
Can you make it so it will show the Max Client's and the current clients along with like refresh??
if you mean capacity, check this thread
[Only registered and activated users can see links. Click Here To Register...]
08/01/2012 09:10 kevin_owner#6
I wouldn't recommend this approach altough I have no idea how non_stop and lastthief's script works.

This one creates the connection in php and is actually real time. The problem is that if you have 50 users watching the server stats you would also have 50 connections to the gateway (Correct me if i'm wrong it could be that php reuses the connection or something).

A better approach would be to use drew's scripts and create a cron job which executes them like every 5 seconds. What you need to do is modify the index.php (I think) and insert/update the current stats into the database.

This way you have only one connection to the gateway and still real time data. Ofcourse you need to write a ajax script to get them into your browser from the database but that isn't too difficult.
08/01/2012 09:54 ÑõÑ_Ŝŧóp#7
our package contains a c# app which connects to the gateway and gets the capacity then inserting it to the database,and the web script is to get the capacity from the database
08/02/2012 22:45 LastThief*#8
Quote:
Originally Posted by ÑõÑ_Ŝŧóp View Post
our package contains a c# app which connects to the gateway and gets the capacity then inserting it to the database,and the web script is to get the capacity from the database
working with ajax tho.
08/03/2012 06:35 theoneofgod#9
Simply cache the result somewhere and work with that.
04/27/2015 20:35 darkmaisej1#10
Cleaner way ^^ (Es gibt auch Object-Orientierung!)

PHP Code:

    
/**
     * Gets the server status
     *
     * @return bool
     */
    
public function getServerStatus()
    {
        
$sIp   $this->_oConfig->getVar("server_ip");      // Server IP
        
$sPort $this->_oConfig->getVar("server_port");  // Server port

        
$blFp = @fsockopen($sIp$sPort$errno$errstr2);

        if (
$blFp) {
            return 
true// Online
        
}

        return 
false// Offline
    

Quote:
Originally Posted by SniuurksT View Post
Add this script to you functions file or somewhere where it includes.
If you want to print the status use this code:

PHP Code:
echo server_status($ip$port); 
PHP Code:
    //Server status script by: SniuurksT
    
$ip '127.0.0.1'//Server ip adress
    
$port '15779'//Server port
    
    
function server_status($ip$port)
    {
    
$status = array("<strong>Server is:</strong><span style='color:#F00;'>Offline</span>""<strong>Server is:</strong><span style='color:#0F0;'>Online </span>
"
);
    
$fp = @fsockopen($ip$port$errno$errstr2);
    if (!
$fp) {
        return 
$status[0];
    } 
    else
      
      { 
      return 
$status[1];
      }
    }