Created
June 10, 2014 09:47
-
-
Save bacinsky/d3ab56647e0757f51c86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHP XCache info for a server monitor | |
*/ | |
$type = !empty($_REQUEST['type']) ? constant($_REQUEST['type']) : XC_TYPE_PHP; | |
$attrib = !empty($_REQUEST['attrib']) ? $_REQUEST['attrib'] : null; | |
$output = null; | |
for ($id = 0; $id < xcache_count($type); $id++) { | |
$info = xcache_info($type, $id); | |
if (empty($attrib) || !isset($info[$attrib])) { | |
throw new \InvalidArgumentException('Expected valid info attrib'); | |
} | |
// join value | |
switch ($attrib) { | |
case 'size': | |
case 'avail': | |
$output+= $info[$attrib]; | |
break; | |
case 'hits_by_second': | |
$output+= round(array_sum($info[$attrib]) / count($info[$attrib]), 2); | |
break; | |
} | |
} | |
// format value | |
switch ($attrib) { | |
case 'size': | |
case 'avail': | |
$callback = function ($output) { | |
return round($output / 1024 / 1024, 2); | |
}; | |
break; | |
default: | |
$callback = function ($output) { | |
return $output; | |
}; | |
} | |
// view | |
echo $callback($output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment