private function initAPCSpec()
 {
     $this->setName(pht('APC'))->setVersion(phpversion('apc'));
     if (ini_get('apc.enabled')) {
         $this->setIsEnabled(true)->setClearCacheCallback('apc_clear_cache');
         $mem = apc_sma_info();
         $this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
         $info = apc_cache_info();
         $this->setUsedMemory($info['mem_size']);
         $write_lock = ini_get('apc.write_lock');
         $slam_defense = ini_get('apc.slam_defense');
         if (!$write_lock || $slam_defense) {
             $summary = pht('Adjust APC settings to quiet unnecessary errors.');
             $message = pht('Some versions of APC may emit unnecessary errors into the ' . 'error log under the current APC settings. To resolve this, ' . 'enable "%s" and disable "%s" in your PHP configuration.', 'apc.write_lock', 'apc.slam_defense');
             $this->newIssue('extension.apc.write-lock')->setShortName(pht('Noisy APC'))->setName(pht('APC Has Noisy Configuration'))->setSummary($summary)->setMessage($message)->addPHPConfig('apc.write_lock')->addPHPConfig('apc.slam_defense');
         }
         $is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
         $is_stat_enabled = ini_get('apc.stat');
         if ($is_stat_enabled && !$is_dev) {
             $summary = pht('"%s" is currently enabled, but should probably be disabled.', 'apc.stat');
             $message = pht('The "%s" setting is currently enabled in your PHP configuration. ' . 'In production mode, "%s" should be disabled. ' . 'This will improve performance slightly.', 'apc.stat', 'apc.stat');
             $this->newIssue('extension.apc.stat-enabled')->setShortName(pht('"%s" Enabled', 'apc.stat'))->setName(pht('"%s" Enabled in Production', 'apc.stat'))->setSummary($summary)->setMessage($message)->addPHPConfig('apc.stat')->addPhabricatorConfig('phabricator.developer-mode');
         } else {
             if (!$is_stat_enabled && $is_dev) {
                 $summary = pht('"%s" is currently disabled, but should probably be enabled.', 'apc.stat');
                 $message = pht('The "%s" setting is currently disabled in your PHP configuration, ' . 'but Phabricator is running in development mode. This option should ' . 'normally be enabled in development so you do not need to restart ' . 'anything after making changes to the code.', 'apc.stat');
                 $this->newIssue('extension.apc.stat-disabled')->setShortName(pht('"%s" Disabled', 'apc.stat'))->setName(pht('"%s" Disabled in Development', 'apc.stat'))->setSummary($summary)->setMessage($message)->addPHPConfig('apc.stat')->addPhabricatorConfig('phabricator.developer-mode');
             }
         }
     } else {
         $this->setIsEnabled(false);
         $this->raiseEnableAPCIssue();
     }
 }
示例#2
0
 function __construct()
 {
     $this->errors = array();
     if (!function_exists('apc_cache_info')) {
         $this->errors[] = "No cache info available.  APC does not appear to be running. ";
         $this->is_valid = false;
     } else {
         $this->time = time();
         foreach (range(1, 10) as $i) {
             self::$allowed_values['AGGR'][$i] = $i;
         }
         $this->host = getenv('HOSTNAME');
         if ($this->host) {
             $this->host = '(' . $this->host . ')';
         }
         $this->apc_all = ini_get_all('apc');
         $this->cache_opcode = apc_cache_info('opcode', 1);
         $this->cache_user = apc_cache_info('user', 1);
         $this->sma_information = apc_sma_info();
         $this->MYREQUEST = array();
         $this->AUTHENTICATED = false;
         $this->require_login = false;
         $this->USE_INTERNAL_AUTHENTICATION = true;
         $this->is_valid = true;
     }
 }
示例#3
0
 /**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     $panel = '';
     # Support for APC
     if (function_exists('apc_sma_info') && ini_get('apc.enabled')) {
         $mem = apc_sma_info();
         $mem_size = $mem['num_seg'] * $mem['seg_size'];
         $mem_avail = $mem['avail_mem'];
         $mem_used = $mem_size - $mem_avail;
         $cache = apc_cache_info();
         $panel .= '<h4>APC ' . phpversion('apc') . ' Enabled</h4>';
         $panel .= round($mem_avail / 1024 / 1024, 1) . 'M available, ' . round($mem_used / 1024 / 1024, 1) . 'M used<br />' . $cache['num_entries'] . ' Files cached (' . round($cache['mem_size'] / 1024 / 1024, 1) . 'M)<br />' . $cache['num_hits'] . ' Hits (' . round($cache['num_hits'] * 100 / ($cache['num_hits'] + $cache['num_misses']), 1) . '%)<br />' . $cache['expunges'] . ' Expunges (cache full count)';
     }
     foreach ($this->_cacheBackends as $name => $backend) {
         $fillingPercentage = $backend->getFillingPercentage();
         $ids = $backend->getIds();
         # Print full class name, backends might be custom
         $panel .= '<h4>Cache ' . $name . ' (' . get_class($backend) . ')</h4>';
         $panel .= count($ids) . ' Entr' . (count($ids) > 1 ? 'ies' : 'y') . '<br />' . 'Filling Percentage: ' . $backend->getFillingPercentage() . '%<br />';
         $cacheSize = 0;
         foreach ($ids as $id) {
             # Calculate valid cache size
             $mem_pre = memory_get_usage();
             if ($cached = $backend->load($id)) {
                 $mem_post = memory_get_usage();
                 $cacheSize += $mem_post - $mem_pre;
                 unset($cached);
             }
         }
         $panel .= 'Valid Cache Size: ' . round($cacheSize / 1024, 1) . 'K';
     }
     return $panel;
 }
示例#4
0
文件: apc.php 项目: bitemyapp/Sblam
 function index()
 {
     /*	$usercache = apc_cache_info('user',false);
     		$entrycount = count($usercache['cache_list']);
     		$usercache = $usercache['cache_list'];
     		$cnt=0;
     		foreach($usercache as $i)
     		{
     			@list($label,$key) = explode(":",$i['info'],2);
     			@list($t,$val) = explode("\t",apc_fetch($i['info']));
     			if ($val<=5) continue;
     
     			$cnt++; if ($cnt > 1000) break;
     
     			if ($key && is_scalar($key)) $tmp[$label][$key] = $val.' '.$i['num_hits'];
     			else $tmp['other'][$i['info']] = $val.' '.$i['num_hits'];
     		}
     		$usercache=NULL;
     		foreach($tmp as &$tmp2)
     		{
     			arsort($tmp2);
     		}
     */
     return array('info' => apc_cache_info(), 'sma' => apc_sma_info(true), 'entrycount' => 0);
 }
示例#5
0
 /**
  */
 function stats()
 {
     if (!$this->is_ready()) {
         return null;
     }
     $info = apc_cache_info();
     $sma = apc_sma_info();
     return ['hits' => isset($info['num_hits']) ? $info['num_hits'] : $info['nhits'], 'misses' => isset($info['num_misses']) ? $info['num_misses'] : $info['nmisses'], 'uptime' => isset($info['start_time']) ? $info['start_time'] : $info['stime'], 'mem_usage' => $info['mem_size'], 'mem_avail' => $sma['avail_mem']];
 }
示例#6
0
文件: ApcGC.php 项目: Nyholm/acache
 /**
  * Run GC with the configured options.
  *
  * @param boolean $force Optional flag to force a run.
  *
  * @return boolean|null The result of the gc or <code>null</code> for a noop.
  */
 public function run($force = false)
 {
     $options = $this->options;
     $now = time();
     if (($mem = apc_sma_info()) && ($force || $now > $this->lastRun + $options['throttle'])) {
         $this->lastRun = $now;
         // calculate what is left
         $size = $mem['num_seg'] * $mem['seg_size'];
         $avail = (double) $mem['avail_mem'];
         $avail_p = (int) sprintf('%d', $avail * 100 / $size);
         // check for clear first because then we do not have to do GC...
         if (null !== $options['clear_percent'] && $options['clear_percent'] > $avail_p) {
             return apc_clear_cache('user');
         }
         if (null !== $options['clear_size'] && $options['clear_size'] > $avail) {
             return apc_clear_cache('user');
         }
         if (null !== $options['clear_f_percent']) {
             // first need to calculate current fragmentation
             $frag = 0;
             $nseg = $freeseg = $fragsize = $freetotal = 0;
             for ($ii = 0; $ii < $mem['num_seg']; ++$ii) {
                 $ptr = 0;
                 foreach ($mem['block_lists'][$ii] as $block) {
                     if ($block['offset'] != $ptr) {
                         ++$nseg;
                     }
                     $ptr = $block['offset'] + $block['size'];
                     if ($block['size'] < $options['f_block_size'] * 1024 * 1024) {
                         $fragsize += $block['size'];
                     }
                     $freetotal += $block['size'];
                 }
                 $freeseg += count($mem['block_lists'][$ii]);
             }
             if ($freeseg > 1) {
                 $frag = (int) sprintf('%d', $fragsize / $freetotal * 100 * 100);
                 if ($frag > $options['clear_f_percent']) {
                     return apc_clear_cache('user');
                 }
             }
         }
         // GC
         if (null !== $options['trigger_percent'] && $options['trigger_percent'] > $avail_p || null !== $options['trigger_size'] && $options['trigger_size'] > $avail) {
             $now = time();
             $cacheInfo = apc_cache_info('user');
             foreach ($cacheInfo['cache_list'] as $entry) {
                 if ($entry['ttl'] && $entry['creation_time'] + $entry['ttl'] + $options['grace_period'] < $now) {
                     // expired and past grace period
                     apc_delete($entry['info']);
                 }
             }
             return true;
         }
     }
     return;
 }
示例#7
0
 /**
  * Identify whether the caching method is currently available
  * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
  *
  * @return  boolean
  */
 public static function cacheMethodIsAvailable()
 {
     if (!function_exists('apc_store')) {
         return false;
     }
     if (apc_sma_info() === false) {
         return false;
     }
     return true;
 }
示例#8
0
 /**
  * @inheritdoc
  */
 public function status()
 {
     $cache_info = apc_cache_info();
     $sma_info = apc_sma_info();
     $status[self::HITS] = isset($cache_info['nhits']) ? $cache_info['nhits'] : 0;
     $status[self::MISSES] = isset($cache_info['nmisses']) ? $cache_info['nmisses'] : 0;
     $status[self::START_TIME] = isset($cache_info['stime']) ? $cache_info['stime'] : 0;
     $status[self::MEMORY_USED] = isset($cache_info['mem_size']) ? $cache_info['mem_size'] : 0;
     $status[self::MEMORY_LEFT] = isset($sma_info['avail_mem']) ? $sma_info['avail_mem'] : 0;
     return $status;
 }
示例#9
0
 public function getStatistic()
 {
     $result = array();
     $cache_user = apc_cache_info('user', 1);
     $result['version'] = phpversion('apc');
     $result['curr_items'] = $cache_user['num_entries'];
     $result['bytes'] = $cache_user['mem_size'];
     $mem = apc_sma_info();
     $result['limit_maxbytes'] = $mem['avail_mem'];
     return $result;
 }
示例#10
0
文件: apc.php 项目: syjzwjj/quyeba
 public function status()
 {
     $minfo = apc_sma_info();
     $cinfo = apc_cache_info('user');
     foreach ($minfo['block_lists'] as $c) {
         $blocks[] = count($c);
     }
     $return['缓存命中'] = $cinfo['num_hits'];
     $return['缓存未命中'] = $cinfo['num_misses'];
     $return['可用内存'] = $minfo['avail_mem'];
     return $return;
 }
示例#11
0
 /**
  * {@inheritdoc}
  */
 protected function doGetStats()
 {
     $info = apc_cache_info('', true);
     $sma = apc_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']);
 }
示例#12
0
文件: Cache.php 项目: tavy315/zfdebug
 /**
  * Gets content panel for the Debug Bar
  *
  * @return string
  */
 public function getPanel()
 {
     $panel = '';
     $linebreak = $this->getLinebreak();
     # Support for APC
     if (function_exists('apc_sma_info') && ini_get('apc.enabled')) {
         $mem = apc_sma_info();
         $memSize = $mem['num_seg'] * $mem['seg_size'];
         $memAvail = $mem['avail_mem'];
         $memUsed = $memSize - $memAvail;
         $cache = apc_cache_info();
         $numEntries = isset($cache['num_entries']) ? $cache['num_entries'] : 0;
         $numHits = isset($cache['num_hits']) ? $cache['num_hits'] : 0;
         $numMisses = isset($cache['num_misses']) ? $cache['num_misses'] : 0;
         $expunges = isset($cache['expunges']) ? $cache['expunges'] : '';
         if ($cache['mem_size'] > 0) {
             $panel .= '<h4>APC ' . phpversion('apc') . ' Enabled</h4>';
             $panel .= round($memAvail / 1024 / 1024, 1) . 'M available, ' . round($memUsed / 1024 / 1024, 1) . 'M used' . $linebreak . $numEntries . ' Files cached (' . round($cache['mem_size'] / 1024 / 1024, 1) . 'M)' . $linebreak . $numHits . ' Hits (' . round($numHits * 100 / ($numHits + $numMisses), 1) . '%)' . $linebreak . $expunges . ' Expunges (cache full count)';
         }
     }
     if (function_exists('opcache_get_configuration')) {
         $opconfig = opcache_get_configuration();
         if ($opconfig['directives']['opcache.enable']) {
             $opstatus = opcache_get_status();
             $cache = $opstatus['opcache_statistics'];
             $panel .= '<h4>' . $opconfig['version']['opcache_product_name'] . ' ' . $opconfig['version']['version'] . ' Enabled</h4>';
             $panel .= round($opstatus['memory_usage']['used_memory'] / 1024 / 1024, 1) . 'M used, ' . round($opstatus['memory_usage']['free_memory'] / 1024 / 1024, 1) . 'M free (' . round($opstatus['memory_usage']['current_wasted_percentage'], 1) . '% wasted)' . $linebreak . $cache['num_cached_scripts'] . ' Files cached' . $linebreak . $cache['hits'] . ' Hits (' . round($cache['opcache_hit_rate'], 1) . '%)';
         }
     }
     /** @var \Zend_Cache_Backend_ExtendedInterface $backend */
     foreach ($this->cacheBackends as $name => $backend) {
         $fillingPercentage = $backend->getFillingPercentage();
         $ids = $backend->getIds();
         # Print full class name, backends might be custom
         $panel .= '<h4>Cache ' . $name . ' (' . get_class($backend) . ')</h4>';
         $panel .= count($ids) . ' Entr' . (count($ids) > 1 ? 'ies' : 'y') . '' . $linebreak . 'Filling Percentage: ' . $fillingPercentage . '%' . $linebreak;
         $cacheSize = 0;
         foreach ($ids as $id) {
             # Calculate valid cache size
             $memPre = memory_get_usage();
             if ($cached = $backend->load($id)) {
                 $memPost = memory_get_usage();
                 $cacheSize += $memPost - $memPre;
                 unset($cached);
             }
         }
         $panel .= 'Valid Cache Size: ' . round($cacheSize / 1024, 1) . 'K';
     }
     // adds form to clear the cache
     $panel .= '<h4>Clear cache</h4>' . $linebreak . '<form method="post"><button name="clear_cache" type="submit" class="btn">Clear cache</button></form>';
     return $panel;
 }
示例#13
0
 /**
  * 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('apc')) {
         $memoryInfo = @apc_sma_info();
         $availableMemory = $memoryInfo['avail_mem'];
         // If more than 5MB free
         if ($availableMemory > 5 * 1024 * 1024) {
             $result = true;
         }
     }
     return $result;
 }
示例#14
0
 /**
  * @param string $type The cache's type
  *
  * @return boolean
  */
 public function info($type = null)
 {
     if ($type != null && $type != self::CACHE_INFO_TYPE_FILEHITS && $type != self::CACHE_INFO_TYPE_USER && type != self::CACHE_INFO_TYPE_SYSTEM) {
         throw new \InvalidArgumentException("Unknown cache's type for value : " . $type . " !");
     }
     switch ($type) {
         case self::CACHE_INFO_TYPE_SYSTEM:
             return apc_sma_info();
         case self::CACHE_INFO_TYPE_SYSTEM_FULL:
             return apc_sma_info(false);
     }
     return apc_cache_info($type);
 }
 /**
  * render method
  *
  * Generate output of APC memory statistics, if accessible
  *
  * @param Ai1ec_Apc_Cache $instance Allegedly used Apc_Cache instance
  *
  * @return string Output to include in log, with APC statistics
  */
 public function render($instance)
 {
     $output = '';
     if (is_callable('ini_get')) {
         $output .= 'SHM:' . ini_get('apc.shm_size');
     }
     if (function_exists('apc_sma_info')) {
         $sma_info = apc_sma_info();
         $output .= $sma_info['seg_size'] - $sma_info['avail_mem'] . 'b / ' . $sma_info['seg_size'] . 'b over ' . $sma_info['num_seg'] . ' segments';
         unset($sma_info);
     }
     return $output;
 }
示例#16
0
 /**
  * APC preset is available if extension is loaded, if APC has ~100MB
  * memory and if ~5MB are free.
  *
  * @return boolean TRUE
  */
 public function isAvailable()
 {
     $result = FALSE;
     if (extension_loaded('apc')) {
         $memoryInfo = @apc_sma_info();
         $totalMemory = $memoryInfo['num_seg'] * $memoryInfo['seg_size'];
         $availableMemory = $memoryInfo['avail_mem'];
         // If more than 99MB in total and more than 5MB free
         if ($totalMemory > 99 * 1024 * 1024 && $availableMemory > 5 * 1024 * 1024) {
             $result = TRUE;
         }
     }
     return $result;
 }
示例#17
0
 public function apc()
 {
     Meta::set('title', __('Cache: APC'));
     if (!function_exists('apc_cache_info')) {
         return View::make('admin::molecules.alert-extends', ['extends' => 'management.cache.layout', 'section' => 'subcontent', 'status' => 'danger', 'message' => __('You have not enabled APC in your system')]);
     }
     if (is_object($processor = $this->processor(__FUNCTION__))) {
         return $processor;
     }
     $stats = apc_sma_info();
     $total = $stats['num_seg'] * $stats['seg_size'];
     $used = $total - $stats['avail_mem'];
     return self::view('management.cache.apc', ['total' => round($total / 1024 / 1024), 'used' => round($used / 1024 / 1024), 'percent' => round($used * 100 / $total)]);
 }
示例#18
0
 /**
  * Constructor
  *
  * @param array $config
  *
  * @see http://jp.php.net/manual/ja/function.Apc-addserver.php
  * @throws BEAR_Cache_Exception
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $app = BEAR::get('app');
     $this->_config['info'] = $config['info'];
     if (!extension_loaded('apc') || !ini_get('apc.enabled') || !function_exists('apc_sma_info')) {
         throw new BEAR_Cache_Exception('APC extention is not loaded');
     } else {
         if ($this->_config['debug']) {
             $apcSmaInfo = apc_sma_info();
             BEAR::dependency('BEAR_Log')->log('APC', $apcSmaInfo);
         }
     }
 }
示例#19
0
 public function getUsage()
 {
     if ($this->usage === null) {
         $info = apc_sma_info();
         $user = apc_cache_info('user');
         $user['total_hits'] = $user['num_hits'] + $user['num_misses'];
         $user['query_sec'] = $this->formatNum($user['total_hits'] / (microtime(true) - $user['start_time']));
         $system = apc_cache_info();
         $system['total_hits'] = $system['num_hits'] + $system['num_misses'];
         $system['query_sec'] = $this->formatNum($system['total_hits'] / (microtime(true) - $system['start_time']));
         $this->percent_used = $this->formatNum(($info['seg_size'] * $info['num_seg'] - $info['avail_mem']) * 100 / ($info['seg_size'] * $info['num_seg']));
         $this->usage = array('Resources' => array('Segments' => $info['num_seg'], 'Segment size' => $this->formatBytes($info['seg_size']), 'Total memory' => $this->formatBytes($info['seg_size'] * $info['num_seg']), 'Used memory' => $this->formatBytes($info['seg_size'] * $info['num_seg'] - $info['avail_mem']), 'Available memory' => $this->formatBytes($info['avail_mem'])), 'User' => array('Used memory' => $this->formatBytes($user['mem_size']), 'Queries / second' => $user['query_sec'], 'Hits' => $user['num_hits'] . ' (' . $this->formatNum($user['num_hits'] * 100 / ($user['total_hits'] ?: 1)) . '%)', 'Misses' => $user['num_misses'] . ' (' . $this->formatNum($user['num_misses'] * 100 / ($user['total_hits'] ?: 1)) . '%)', 'Inserts' => $user['num_inserts'], 'Deletes' => count($user['deleted_list']), 'Items' => $user['num_entries']), 'System' => array('Used memory' => $this->formatBytes($system['mem_size']), 'Queries / second' => $system['query_sec'], 'Hits' => $system['num_hits'] . ' (' . $this->formatNum($system['num_hits'] * 100 / ($system['total_hits'] ?: 1)) . '%)', 'Misses' => $system['num_misses'] . ' (' . $this->formatNum($system['num_misses'] * 100 / ($system['total_hits'] ?: 1)) . '%)', 'Inserts' => $system['num_inserts'], 'Deletes' => count($system['deleted_list']), 'Files' => $system['num_entries']));
     }
     return $this->usage;
 }
示例#20
0
 public function actionIndex()
 {
     $formatter = new CustomFormatter();
     $userCacheInfo = apc_cache_info('user');
     $fileCacheInfo = apc_cache_info('opcode');
     $mem = apc_sma_info();
     $iniSettings = array();
     foreach (ini_get_all('apc') as $id => $settings) {
         $iniSettings[] = array('id' => $id, 'local' => $settings['local_value'], 'global' => $settings['global_value'], 'access' => $settings['access']);
     }
     $info = array('apc_version' => phpversion('apc'), 'php_version' => phpversion(), 'host' => $_SERVER['SERVER_NAME'] . ' (' . php_uname('n') . ' [' . $_SERVER['SERVER_ADDR'] . '])', 'server_software' => $_SERVER['SERVER_SOFTWARE'], 'shared_memory' => "{$mem['num_seg']} Segment(s) with {$formatter->formatDatasize($mem['seg_size'])}", 'memory_type' => "{$fileCacheInfo['memory_type']} with {$fileCacheInfo['locking_type']}", 'start_time' => $fileCacheInfo['start_time'], 'file_upload_support' => $fileCacheInfo['file_upload_progress']);
     $delta = $_SERVER['REQUEST_TIME'] - $fileCacheInfo['start_time'];
     if ($delta === 0) {
         $delta = 1;
     }
     //prevent div by zero
     $fileCache = array('cached_files' => $fileCacheInfo['num_entries'], 'cached_file_size' => $fileCacheInfo['mem_size'], 'hits' => $fileCacheInfo['num_hits'], 'misses' => $fileCacheInfo['num_misses'], 'request_rate' => ($fileCacheInfo['num_hits'] + $fileCacheInfo['num_misses']) / $delta, 'hit_rate' => $fileCacheInfo['num_hits'] / $delta, 'miss_rate' => $fileCacheInfo['num_misses'] / $delta, 'insert_rate' => $fileCacheInfo['num_inserts'] / $delta, 'cache_full_count' => $fileCacheInfo['expunges']);
     $delta = $_SERVER['REQUEST_TIME'] - $userCacheInfo['start_time'];
     if ($delta === 0) {
         $delta = 1;
     }
     //prevent div by zero
     $userCache = array('cached_entries' => $userCacheInfo['num_entries'], 'cached_entry_size' => $userCacheInfo['mem_size'], 'hits' => $userCacheInfo['num_hits'], 'misses' => $userCacheInfo['num_misses'], 'request_rate' => ($userCacheInfo['num_hits'] + $userCacheInfo['num_misses']) / $delta, 'hit_rate' => $userCacheInfo['num_hits'] / $delta, 'miss_rate' => $userCacheInfo['num_misses'] / $delta, 'insert_rate' => $userCacheInfo['num_inserts'] / $delta, 'cache_full_count' => $userCacheInfo['expunges']);
     $position = 0;
     $freesegs = 0;
     $fragsize = 0;
     $freetotal = 0;
     $blocks = array();
     foreach ($mem['block_lists'] as $i => $list) {
         uasort($list, array($this, 'blockSort'));
         foreach ($list as $block) {
             if ($position != $block['offset']) {
                 $blocks[] = array('segment' => $i, 'free' => false, 'offset' => $position, 'size' => $block['offset'] - $position, 'percent' => 100 * ($block['offset'] - $position) / $mem['seg_size']);
             }
             $blocks[] = array('segment' => $i, 'free' => true, 'offset' => $block['offset'], 'size' => $block['size'], 'percent' => 100 * $block['size'] / $mem['seg_size']);
             $position = $block['offset'] + $block['size'];
             if ($block['size'] < 5 * 1024 * 024) {
                 $fragsize += $block['size'];
             }
             $freetotal += $block['size'];
         }
         $freesegs += count($list);
     }
     if ($position < $mem['seg_size']) {
         $blocks[] = array('segment' => $i, 'free' => false, 'offset' => $position, 'size' => $smaInfo['seg_size'] - $position, 'percent' => 100 * ($mem['seg_size'] - $position) / $mem['seg_size']);
     }
     $this->render('index', array('formatter' => $formatter, 'fileCache' => $fileCache, 'fileCacheList' => $fileCacheInfo['cache_list'], 'userCache' => $userCache, 'userCacheList' => $userCacheInfo['cache_list'], 'iniSettings' => $iniSettings, 'info' => $info, 'blocks' => $blocks, 'fragInfo' => array('freesegs' => $freesegs, 'fragsize' => $fragsize, 'freetotal' => $freetotal)));
 }
示例#21
0
 /**
  * Perform the check
  *
  * @see \ZendDiagnostics\Check\CheckInterface::check()     *
  * @return Failure|Skip|Success|Warning
  */
 public function check()
 {
     if (!ini_get('apc.enabled')) {
         return new Skip('APC has not been enabled or installed.');
     }
     if (php_sapi_name() == 'cli' && !ini_get('apc.enabled_cli')) {
         return new Skip('APC has not been enabled in CLI.');
     }
     if (!function_exists('apc_sma_info')) {
         return new Warning('APC extension is not available');
     }
     if (!($this->apcInfo = apc_sma_info())) {
         return new Warning('Unable to retrieve APC memory status information.');
     }
     return parent::check();
 }
示例#22
0
 function status(&$curBytes, &$totalBytes)
 {
     $minfo = apc_sma_info();
     $cinfo = apc_cache_info('user');
     foreach ($minfo['block_lists'] as $c) {
         $blocks[] = count($c);
     }
     $curBytes = $minfo['seg_size'] - $minfo['avail_mem'];
     $totalBytes = $minfo['seg_size'];
     $return[] = array('name' => '子系统运行时间', 'value' => timeLength(time() - $cinfo['start_time']));
     $return[] = array('name' => '可用内存', 'value' => formatBytes($minfo['avail_mem']) . ' / ' . formatBytes($minfo['seg_size']));
     $return[] = array('name' => '内存使用方式', 'value' => $cinfo['memory_type']);
     $return[] = array('name' => '内存数据段', 'value' => $minfo['num_seg'] . '块 (' . implode(',', $blocks) . ')');
     $return[] = array('name' => '缓存命中', 'value' => $cinfo['num_hits'] . '次');
     $return[] = array('name' => '缓存未命中', 'value' => $cinfo['num_misses'] . '次');
     $return[] = array('name' => '已缓存数据条数', 'value' => $cinfo['num_entries'] . '条');
     $return[] = array('name' => '数据锁定方式', 'value' => $cinfo['locking_type']);
     return $return;
 }
示例#23
0
 /**
  * Perform the check
  *
  * @see \ZendDiagnostics\Check\CheckInterface::check()
  * @return Failure|Skip|Success|Warning
  */
 public function check()
 {
     if (!ini_get('apc.enabled')) {
         return new Skip('APC has not been enabled or installed.');
     }
     if (php_sapi_name() == 'cli' && !ini_get('apc.enabled_cli')) {
         return new Skip('APC has not been enabled in CLI.');
     }
     if (!function_exists('apc_sma_info')) {
         return new Warning('APC extension is not available');
     }
     if (!($info = apc_sma_info())) {
         return new Warning('Unable to retrieve APC memory status information.');
     }
     $nseg = $freeseg = $fragsize = $freetotal = 0;
     for ($i = 0; $i < $info['num_seg']; $i++) {
         $ptr = 0;
         foreach ($info['block_lists'][$i] as $block) {
             if ($block['offset'] != $ptr) {
                 ++$nseg;
             }
             $ptr = $block['offset'] + $block['size'];
             /* Only consider blocks <5M for the fragmentation % */
             if ($block['size'] < 5 * 1024 * 1024) {
                 $fragsize += $block['size'];
             }
             $freetotal += $block['size'];
         }
         $freeseg += count($info['block_lists'][$i]);
     }
     $fragPercent = 0;
     if ($freeseg > 1) {
         $fragPercent = $fragsize / $freetotal * 100;
     }
     $message = sprintf('%.0f%% memory fragmentation.', $fragPercent);
     if ($fragPercent > $this->criticalThreshold) {
         return new Failure($message);
     }
     if ($fragPercent > $this->warningThreshold) {
         return new Warning($message);
     }
     return new Success($message);
 }
示例#24
0
 /**
  * Perform the check
  *
  * @see \ZendDiagnostics\Check\CheckInterface::check()     *
  * @return Failure|Skip|Success|Warning
  */
 public function check()
 {
     if (!function_exists('apc_sma_info')) {
         return new Warning('APC extension is not available');
     }
     if (!($info = apc_sma_info())) {
         return new Warning('Unable to retrieve APC memory status information.');
     }
     $size = $info['num_seg'] * $info['seg_size'];
     $available = $info['avail_mem'];
     $used = $size - $available;
     $percentUsed = $used / $size * 100;
     $message = sprintf('%.0f%% of available %s memory used.', $percentUsed, $this->formatBytes($size));
     if ($percentUsed > $this->criticalThreshold) {
         return new Failure($message);
     }
     if ($percentUsed > $this->warningThreshold) {
         return new Warning($message);
     }
     return new Success($message);
 }
 private function initAPCCommonSpec()
 {
     $mem = apc_sma_info();
     $this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
     $info = apc_cache_info('user');
     $this->setUsedMemory($info['mem_size']);
     $this->setEntryCount(count($info['cache_list']));
     $cache = $info['cache_list'];
     $state = array();
     foreach ($cache as $item) {
         $info = idx($item, 'info', '<unknown-key>');
         $key = self::getKeyPattern($info);
         if (empty($state[$key])) {
             $state[$key] = array('max' => 0, 'total' => 0, 'count' => 0);
         }
         $state[$key]['max'] = max($state[$key]['max'], $item['mem_size']);
         $state[$key]['total'] += $item['mem_size'];
         $state[$key]['count']++;
     }
     $this->setCacheSummary($state);
 }
	public static function initialize($method = self::cache_in_memory, $arguments = array()) {
		if (! in_array ( $method, self::$_storageMethods )) {
			return false;
		}
		
		switch ($method) {
			case self::cache_to_apc :
				if (! function_exists ( 'apc_store' )) {
					return false;
				}
				if (apc_sma_info () === false) {
					return false;
				}
				break;
			case self::cache_to_memcache :
				if (! function_exists ( 'memcache_add' )) {
					return false;
				}
				break;
			case self::cache_to_wincache :
				if (! function_exists ( 'wincache_ucache_add' )) {
					return false;
				}
				break;
		}
		
		self::$_storageMethodParameters [$method] = self::$_storageMethodDefaultParameters [$method];
		foreach ( $arguments as $k => $v ) {
			if (isset ( self::$_storageMethodParameters [$method] [$k] )) {
				self::$_storageMethodParameters [$method] [$k] = $v;
			}
		}
		
		if (is_null ( self::$_cacheStorageMethod )) {
			self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
			self::$_cacheStorageMethod = $method;
		}
		return true;
	} // function initialize()
示例#27
0
文件: Apc.php 项目: haoyanfei/zf2
 /**
  * Get available space in bytes
  *
  * @return int|float
  */
 public function getAvailableSpace()
 {
     $smaInfo = apc_sma_info(true);
     return $smaInfo['avail_mem'];
 }
示例#28
0
 function __construct()
 {
     $apc_enabled = strtolower(ini_get('apc.enabled'));
     $this->is_enabled = !($apc_enabled == "0" || $apc_enabled == "off");
     $apc_cache_by_default = strtolower(ini_get('apc.cache_by_default'));
     $this->is_cache_by_default = !($apc_cache_by_default == "0" || $apc_cache_by_default == "off");
     $apc_stat = strtolower(ini_get('apc.stat'));
     $this->num_files_hint = intval(ini_get('apc.num_files_hint'));
     $this->user_entries_hint = intval(ini_get('apc.user_entries_hint'));
     $memory = apc_sma_info(true);
     parent::__construct($this->is_enabled && $this->is_cache_by_default, intval(ini_get('apc.ttl')), static::unformat(ini_get('apc.max_file_size')), !($apc_stat == "0" || $apc_stat == "off"), $memory["seg_size"], $memory["seg_size"] - $memory["avail_mem"]);
 }
示例#29
0
文件: APC.php 项目: ahsanmage/vr
 /**
  * Identify whether the caching method is currently available
  * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
  *
  * @return  boolean
  */
 public static function cacheMethodIsAvailable()
 {
     if (!function_exists('apc_store')) {
         return FALSE;
     }
     if (apc_sma_info() === FALSE) {
         return FALSE;
     }
     return TRUE;
 }
示例#30
0
 function apcu_sma_info($limited = false)
 {
     return apc_sma_info($limited);
 }