/** * {@inheritdoc} */ protected function doGetStats() { $info = apcu_cache_info('', true); $sma = apcu_sma_info(); // @TODO - Temporary fix @see https://github.com/krakjoe/apcu/pull/42 if (PHP_VERSION_ID >= 50500) { $info['num_hits'] = isset($info['num_hits']) ? $info['num_hits'] : $info['nhits']; $info['num_misses'] = isset($info['num_misses']) ? $info['num_misses'] : $info['nmisses']; $info['start_time'] = isset($info['start_time']) ? $info['start_time'] : $info['stime']; } return array(Cache::STATS_HITS => $info['num_hits'], Cache::STATS_MISSES => $info['num_misses'], Cache::STATS_UPTIME => $info['start_time'], Cache::STATS_MEMORY_USAGE => $info['mem_size'], Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem']); }
/** * APC preset is available if extension is loaded and at least ~5MB are free. * * @return bool TRUE */ public function isAvailable() { $result = false; if (extension_loaded('apcu')) { $memoryInfo = @apcu_sma_info(); $availableMemory = $memoryInfo['avail_mem']; // If more than 5MB free if ($availableMemory > 5 * 1024 * 1024) { $result = true; } } return $result; }
/** * Is APCu available? * @return bool */ public static function isAvailable() { try { if (!extension_loaded('apcu') or php_sapi_name() == 'cli' or !function_exists('apcu_sma_info')) { return false; } $info = @apcu_sma_info(true); if ($e = error_get_last() and $e['file'] == __FILE__) { return false; } if (empty($info) or empty($info['num_seg'])) { return false; } } catch (\Exception $ex) { return false; } return true; }
} } } // clear cache if ($AUTHENTICATED && isset($MYREQUEST['CC']) && $MYREQUEST['CC']) { apcu_clear_cache(); } if ($AUTHENTICATED && !empty($MYREQUEST['DU'])) { apcu_delete($MYREQUEST['DU']); } if (!function_exists('apcu_cache_info')) { echo "No cache info available. APC does not appear to be running."; exit; } $cache = apcu_cache_info(); $mem = apcu_sma_info(); // don't cache this page // header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 function duration($ts) { global $time; $years = (int) (($time - $ts) / (7 * 86400) / 52.177457); $rem = (int) ($time - $ts - $years * 52.177457 * 7 * 86400); $weeks = (int) ($rem / (7 * 86400)); $days = (int) ($rem / 86400) - $weeks * 7; $hours = (int) ($rem / 3600) - $days * 24 - $weeks * 7 * 24;
/** * Get available space in bytes * * @return int|float */ public function getAvailableSpace() { $smaInfo = apcu_sma_info(true); return $smaInfo['avail_mem']; }
return apc_sma_info($limited); } /** * @param string $type * @param bool $limited * @return array|bool Array of cached data (and meta-data) or FALSE on failure. */ function apcu_cache_info($type = '', $limited = false) { return apc_cache_info($type, $limited); } class APCUIterator extends APCIterator { } } $smaInfo = apcu_sma_info(); $cacheInfo = apcu_cache_info(); ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <table> <tr> <td colspan="2"> <h2>Cache Information</h2> </td>
function apc_sma_info($limited = false) { return apcu_sma_info($limited); }
/** * {@inheritdoc} */ protected function doGetStats() { $info = apcu_cache_info(true); $sma = apcu_sma_info(); return array(Cache::STATS_HITS => $info['num_hits'], Cache::STATS_MISSES => $info['num_misses'], Cache::STATS_UPTIME => $info['start_time'], Cache::STATS_MEMORY_USAGE => $info['mem_size'], Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem']); }
public function getFillingPercentage() { if (php_sapi_name() == 'cli') { return 0; } $mem = apcu_sma_info(true); $memSize = $mem['num_seg'] * $mem['seg_size']; $memAvailable = $mem['avail_mem']; $memUsed = $memSize - $memAvailable; if ($memSize == 0) { Zend_Cache::throwException('can\'t get apc memory size'); } if ($memUsed > $memSize) { return 100; } return (int) (100.0 * ($memUsed / $memSize)); }
public static function handleCacheRequest() { $GLOBALS['Session']->requireAccountLevel('Staff'); $memInfo = apcu_sma_info(true); return static::respond('cacheStatus', ['free' => $memInfo['avail_mem'], 'responses' => Cache::getIterator('/^response:/')->getTotalSize(), 'total' => $memInfo['seg_size']]); }
/** * APCu sma info * @param \Slim\Http\Request $req http request * @param \Slim\Http\Response $res http response */ public function info(Request $req, Response $res) { return $res->withStatus(200)->withHeader('Content-type', 'application/json')->write(json_encode(apcu_sma_info(), JSON_PRETTY_PRINT)); }