本文整理汇总了PHP中apc_sma_info函数的典型用法代码示例。如果您正苦于以下问题:PHP apc_sma_info函数的具体用法?PHP apc_sma_info怎么用?PHP apc_sma_info使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apc_sma_info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initAPCSpec
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: __construct
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: getPanel
/**
* 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: index
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: stats
/**
*/
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: run
/**
* 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: cacheMethodIsAvailable
/**
* 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: status
/**
* @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: getStatistic
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: status
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: doGetStats
/**
* {@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: getPanel
/**
* 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: isAvailable
/**
* 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: info
/**
* @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);
}
示例15: render
/**
* 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;
}