Version 1.0 - works for most servers
Updated 1.1 - optimized code
Updated 1.2 - added names of uncached templates!
Okay, the original was by TECK. This is NOT based on his code - it is based on vB3's native code. If TECK wants me to remove this, I will do so. This is just my version that I use for my private forums.
Information shown:
1) Page loading times
2) Number of Queries
3) Server Loads
4) Number of Any Uncached Templates
5) Name of Uncached Templates (NEW!)
By default only an Admin (usergroup 6) can see it. Feel free to modify this bit.
It's very easy to install.
Open includes/functions.php:
Find:
PHP Code:
// ####################################################################
// temporary code
global $_TEMPLATEQUERIES, $tempusagecache, $DEVDEBUG, $_SERVER, $debug;
UNDERNEATH, ADD:
Version 1.2 - more optimized but requires /proc on your server - try this, if server loads don't show up use Version 1.02 below
PHP Code:
// Microstats hack
if ($bbuserinfo[usergroupid]==6) {
$pageendtime = microtime();
$starttime = explode(' ', $pagestarttime);
$endtime = explode(' ', $pageendtime);
$totaltime = vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5);
$loadavg = @file_get_contents("/proc/loadavg");
if ($loadavg) {
$regs = explode(" ",$loadavg);
$serverload=' [Server Loads: <b>'.$regs[0].'</b> '.$regs[1].' : '.$regs[2].']';
}
$debughtml = "<center><span class=\"smallfont\">Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" . iif($_TEMPLATEQUERIES, " (<b>" . sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)", '') . "$serverload</span></center>";
ksort($tempusagecache);
foreach ($tempusagecache AS $tempname => $times)
{
if ($_TEMPLATEQUERIES["$tempname"]) $debughtml .= "<center><span class=\"smallfont\">Uncached templates: <font color=\"red\"><b>$tempname</b></font> ($times)</span></center>";
}
$vartext = str_replace('</body>', "$debughtml\n</body>", $vartext);
}
//Microstats Hack
Version 1.02 - Use this if Version 1.1 doesn't work for you.
PHP Code:
// Microstats hack
if ($bbuserinfo[usergroupid]==6) {
$pageendtime = microtime();
$starttime = explode(' ', $pagestarttime);
$endtime = explode(' ', $pageendtime);
$totaltime = vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5);
if ($stats=@exec('uptime')) {
preg_match('/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/',$stats,$regs);
$serverload=' [Server Loads: <b>'.$regs[1].'</b> » '.$regs[2].' : '.$regs[3].']';
}
$debughtml = "<center><span class=\"smallfont\">Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" . iif($_TEMPLATEQUERIES, " (<b>" . sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)", '') . "$serverload</span>";
$vartext = str_replace('</body>', "$debughtml\n</body>", $vartext);
ksort($tempusagecache);
foreach ($tempusagecache AS $tempname => $times)
{
if ($_TEMPLATEQUERIES["$tempname"]) $debughtml .= "<center><span class=\"smallfont\">Uncached templates: <font color=\"red\"><b>$tempname</b></font> ($times)</span></center>";
}
}
//Microstats Hack
Done! As simple as that. No need to enable debug mode.
If you want only yourself to have this information, change:
if ($bbuserinfo[usergroupid]==6) {
to
if ($bbuserinfo[userid]==1) {
And replace 1 with your userid.
To let everyone see it, remove that line, and the last } of the code above.
Below is a screenshot of how my forumhome microstats look.
EDIT: Thanks to kmike, I optimized the code. This should lessen the load when checking the server loads slightly.
Version 1.2 and 1.02 now has added code to show NAMES OF UNCACHED TEMPLATES!