[MOD] Server Uptime

Modifications for phpBB3.
Try the Mods here and share Your own Mods
Forum rules
You dont have to use ModX or make your mod AutoMod compatible. A simple textfile is fine
But if you post Mods here You also have to give support

[MOD] Server Uptime

Post by Stoker »

I have created a nice little script for my self that displays your servers uptime and average load.
You will find it in the statistics section both on the portal and on forum index:

Server uptime 98 days, 15 hours, 38 minutes and 32 seconds
Average load 0.07 • 0.03 • 0.01


I will show you how to add it on index

Open index.php
Find:

Code: Select all

$total_users	= $config['num_users'];
After add:

Code: Select all

$uptimeindex 	= shell_exec("cut -d. -f1 /proc/uptime");
$daysindex 		= floor($uptimeindex/60/60/24);
$hoursindex 	= $uptimeindex/60/60%24;
$minsindex 		= $uptimeindex/60%60;
$secsindex 		= $uptimeindex%60;
$load 			= sys_getloadavg();
Find:

Code: Select all

'NEWEST_USER'	=> sprintf($user->lang['NEWEST_USER'], get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])),
After add:

Code: Select all

	'UPTIME_DAYS'		=> $daysindex,
	'UPTIME_HOURS'		=> $hoursindex,
	'UPTIME_MINS'		=> $minsindex,
	'UPTIME_SECS'		=> $secsindex,
	'AVG_LOAD0'			=> $load[0],
	'AVG_LOAD1'			=> $load[1],
	'AVG_LOAD2'			=> $load[2],

Open styles/prosilver/template/index_body.html
Find:

Code: Select all

<p>{TOTAL_POSTS} &bull; {TOTAL_TOPICS} &bull; {TOTAL_USERS} &bull; {NEWEST_USER}
Inline, After add:

Code: Select all

<br />
	{L_SERVER_UPTIME}: <strong>{UPTIME_DAYS}</strong> days, <strong>{UPTIME_HOURS}</strong> hours, <strong>{UPTIME_MINS}</strong> minutes and <strong>{UPTIME_SECS}</strong> seconds<br />
	{L_AVERAGE_LOAD}: <strong>{AVG_LOAD0}</strong> &bull; <strong>{AVG_LOAD1}</strong> &bull; <strong>{AVG_LOAD2}</strong>
Open language/en/common.php
Find:

Code: Select all

?>
Add before:

Code: Select all

// Server Uptime
$lang = array_merge($lang, array(
   'SERVER_UPTIME'   	 		=> 'Server uptime',
   'AVERAGE_LOAD'			   	=> 'Average load',
));

Re: [MOD] Server Uptime

Post by Daniel »

Nice one. Now this will only work if the host in question have not disabled shell_exec right?

Re: [MOD] Server Uptime

Post by Stoker »

Yes, for Server uptime. But not for Average load as far as I know.

Re: [MOD] Server Uptime

Post by Stoker »

Seems to be working fine with exec too.

[MOD] Server Uptime

Post by martin123456 »

This script did and does work on localhost as i had it before but this time around im testing it on premod

Fatal error: Call to undefined function sys_getloadavg() in D:\xampp\htdocs\index.php on line 39

line 39

Code: Select all

$load            = sys_getloadavg();
remove this line and the site will open up as normal put this line back and get the above error

[MOD] Server Uptime

Post by Stoker »

What is your php version?
Looks like it must be +5.2.1

[MOD] Server Uptime

Post by martin123456 »

XAMPP
[PHP: 5.3.1]

[MOD] Server Uptime

Post by Stoker »

I dont know what the problem is, other than its your server setup.

[MOD] Server Uptime

Post by martin123456 »

It worked once so il try it on a fresh install of premod and fresh database

just updated to PHP: 5.3.8 so will test on that

is a no go on PHP Version 5.3.8 as well so it looks like this no longer works on xampp

[MOD] Server Uptime

Post by Solidjeuh »

Sweeeeeeet! Thank you!

• Server uptime: 6 days, 19 hours, 22 minutes and 11 seconds
• Average load: 0.13 • 0.23 • 0.14

:D