Skip to content

Instantly share code, notes, and snippets.

@bacinsky
Created June 10, 2014 09:47
Show Gist options
  • Save bacinsky/d3ab56647e0757f51c86 to your computer and use it in GitHub Desktop.
Save bacinsky/d3ab56647e0757f51c86 to your computer and use it in GitHub Desktop.
<?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