Jump to content
Sign in to follow this  
Shako

Request [PHP] Server Info Script

Recommended Posts

Hello guys! I'm just trying to figure out how to write a simple server information script.

 

I want to put each aspect into their own separate variables.

Such as:

 

$online_players = "Amount_of_online_players_in_server"

$characters_server = "The amount of characters in the server"

 

All with mssql queries. :)

 

 


logo-big.png   logo.png

                                   Sunny Go! Online                                                                    pko.host                                                 

Share this post


Link to post
Share on other sites

Hello @Shako!

 

Here you are:

<?php

// MSSQL Server settings
$db_host = '';
$db_user = '';
$db_pass = '';

// Our statistics
$online_number = 0;
$total_number = 0;

// Let's connect to DB
$db_connection = @mssql_connect($db_host, $db_user, $db_pass);
if ($db_connection == false) {
	die('<b>Error:</b> Cannot connect to MSSQL Server!');
}

// Getting online character number
$sql = 'SELECT COUNT(*) as number FROM GameDB.dbo.character WHERE mem_addr > 0';
$query = @mssql_query($sql);
if ($query == false) {
	die('<b>Error:</b> Cannot make query to get online character number!');
}

$row = mssql_fetch_object($query);
$online_number = $row->number; // 'number' is the name of field in query 'SELECT COUNT(*) as number ...'

// Getting total character number
$sql = 'SELECT COUNT(*) as total FROM GameDB.dbo.character WHERE delflag = 0';
$query = @mssql_query($sql);
if ($query == false) {
	die('<b>Error:</b> Cannot make query to get total character number!');
}

$row = mssql_fetch_object($query);
$total_number = $row->total;


// Closing DB connection (not neccessary)
mssql_close($db_connection);

?>


<html>

	<head>
		<title>Server statistics</title>
	</head>
	
	<body>
		<h1>Server statistics</h1>
		<p>Total characters: <?php echo $total_number; ?></p>
		<p>Online characters: <?php echo $online_number; ?></p>
	</body>

</html>

 

  • Like 2

Share this post


Link to post
Share on other sites

@V3ct0r Amazing! I will try it out soon.

 

Also, for example I want to make a web link:

 

https://mywebsite.com/page.php into something like

 

https://mywebsite.com/index.php?act=page

 

How would I do it? Thanks!


logo-big.png   logo.png

                                   Sunny Go! Online                                                                    pko.host                                                 

Share this post


Link to post
Share on other sites

@V3ct0r it works. Big thanks! 

 

One more question,, how do I make Max Players Online?

 

and would it be better to keep these information in a text database cached every X seconds?

Edited by Shako

logo-big.png   logo.png

                                   Sunny Go! Online                                                                    pko.host                                                 

Share this post


Link to post
Share on other sites
Quote

and would it be better to keep these information in a text database cached every X seconds?

 

1: use a middleware file with a timestamp inside(try to lock, and unlock it when you finish *if your lock success)

if your LOCK success, compare dates ( now > lastupdate + X seconds ?

and then re-call you query and store its result into a file, otherwise use a cached one

 

2: make a crontab/cron or winTask pointed to an script who record these result into cache files every X time

 

 

------------------------------------ a deleted answer was here ---------------------------------------- [I never noticed that was max online characters xD]

 

 

Quote

One more question,, how do I make Max Players Online?

Does your/s server work with [stat_log]?

if it does:

SELECT MAX(play_num) MaxChaOnline FROM [stat_log]

 

Edited by Totoka
+link
  • Like 1

Discord: andresc

Share this post


Link to post
Share on other sites
7 часов назад, Shako сказал:

@V3ct0r Amazing! I will try it out soon.

 

Also, for example I want to make a web link:

 

https://mywebsite.com/page.php into something like

 

https://mywebsite.com/index.php?act=page

 

How would I do it? Thanks!

Do you use PKOSite? You can make a new page with statistics following the example of existing pages.

 

Цитата

One more question,, how do I make Max Players Online?

As @Totoka wrote, you can use SQL query:

SELECT MAX(play_num) as max_online FROM GameDB.dbo.stat_log
$max_online = 0;
// Getting max online record
$sql = 'SELECT MAX(play_num) as max_online FROM GameDB.dbo.stat_log';
$query = @mssql_query($sql);
if ($query == false) {
	die('<b>Error:</b> Cannot make query to get total max online record!');
}

$row = mssql_fetch_object($query);
$max_online = $row->max_online;
<p>Max online: <?php echo $max_online; ?></p>
Цитата

and would it be better to keep these information in a text database cached every X seconds?

Sure. It will increase the performance and reduce the load

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...