コード例 #1
0
 /**
  * clear static cache with prefix, don't use except in clear-cache-watcher
  *
  * @internal
  */
 public static function clear($cacheIdPrefix)
 {
     if (extension_loaded('apc')) {
         if (PHP_SAPI == 'cli') {
             Kwf_Util_Apc::callClearCacheByCli(array('clearCacheSimpleStatic' => $cacheIdPrefix));
         } else {
             if (!class_exists('APCIterator')) {
                 throw new Kwf_Exception_NotYetImplemented("We don't want to clear the whole");
             } else {
                 static $prefix;
                 if (!isset($prefix)) {
                     $prefix = Kwf_Cache_Simple::getUniquePrefix() . '-';
                 }
                 $it = new APCIterator('user', '#^' . preg_quote($prefix . $cacheIdPrefix) . '#', APC_ITER_NONE);
                 if ($it->getTotalCount() && !$it->current()) {
                     //APCIterator is borked, delete everything
                     //see https://bugs.php.net/bug.php?id=59938
                     if (extension_loaded('apcu')) {
                         apc_clear_cache();
                     } else {
                         apc_clear_cache('user');
                     }
                 } else {
                     //APCIterator seems to work, use it for deletion
                     apc_delete($it);
                 }
             }
         }
     } else {
         //don't use $cacheIdPrefix as filenames are base64 encoded
         foreach (glob('cache/simple/*') as $f) {
             unlink($f);
         }
     }
 }
コード例 #2
0
ファイル: stats.php プロジェクト: Zandemmer/HackThisSite-Old
 public function index()
 {
     if (!CheckAcl::can('viewStats')) {
         return Error::set('You are not allowed to view stats!');
     }
     $info = new APCIterator('user');
     $redis = new redisInfo(ConnectionFactory::get('redis'));
     $redisInfo = $redis->info();
     $this->view['apcNoKeys'] = $info->getTotalCount();
     $this->view['apcSize'] = $info->getTotalSize();
     $this->view['redisVersion'] = $redisInfo['redis_version'];
     $this->view['redisSIP'] = $redisInfo['bgsave_in_progress'];
     $this->view['redisNoChans'] = $redisInfo['pubsub_channels'];
     $this->view['redisMem'] = $redisInfo['used_memory'];
     $this->view['redisLastSave'] = $redisInfo['last_save_time'];
     $this->view['valid'] = true;
 }
コード例 #3
0
ファイル: FlushController.php プロジェクト: Andyyang1981/pi
 /**
  * List of caches
  *
  * @return void
  */
 public function indexAction()
 {
     $type = $this->params('type');
     $cacheList = array('stat' => _a('File status cache'), 'apc' => _a('APC file cache'), 'file' => _a('System cache files'), 'persist' => _a('System persistent data'), 'module' => _a('Module cache'), 'comment' => _a('Comment cache'));
     if (!function_exists('apc_clear_cache')) {
         unset($cacheList['apc']);
     } elseif (class_exists('\\APCIterator')) {
         $apcIterator = new \APCIterator('file');
         $size = $apcIterator->getTotalSize();
         foreach (array('', 'K', 'M', 'G') as $i => $k) {
             if ($size < 1024) {
                 break;
             }
             $size /= 1024;
         }
         $totalSize = sprintf("%5.1f %s", $size, $k);
         $totalCount = $apcIterator->getTotalCount();
         $cacheList['apc'] .= ' (' . $totalCount . '-' . $totalSize . ')';
     }
     $cacheStorageClass = get_class(Pi::service('cache')->storage());
     $cacheStorageName = substr($cacheStorageClass, strrpos($cacheStorageClass, '\\') + 1);
     $cacheList['application'] = sprintf(_a('Application cache [%s]'), $cacheStorageName);
     $frontConfig = Pi::config()->load('application.front.php');
     if (!empty($frontConfig['resource']['cache'])) {
         if (!empty($frontConfig['resource']['cache']['storage'])) {
             $cacheStorage = Pi::service('cache')->loadStorage($frontConfig['resource']['cache']['storage']);
         } else {
             $cacheStorage = Pi::service('cache')->storage();
         }
         $cacheStorageClass = get_class($cacheStorage);
         $cacheStorageName = substr($cacheStorageClass, strrpos($cacheStorageClass, '\\') + 1);
         $page['title'] = sprintf(_a('Page cache [%s]'), $cacheStorageName);
         $modules = Pi::service('module')->meta();
         $page['modules'] = array_keys($modules);
         $this->view()->assign('page', $page);
     }
     $registryList = Pi::service('registry')->getList();
     sort($registryList);
     $this->view()->assign('type', $type);
     $this->view()->assign('list', $cacheList);
     $this->view()->assign('registry', $registryList);
     $this->view()->assign('title', _a('Cache list'));
     //$this->view()->setTemplate('cache-list');
 }
コード例 #4
0
ファイル: Apc.php プロジェクト: xiaoguizhidao/koala-framework
 public static function iterate()
 {
     header('Content-Type: text/plain; charset=utf-8');
     $requiredSpazi = 1024 * 1024 * 128;
     //128MB
     //$requiredSpazi = 1024*1024*300;
     $mem = apc_sma_info(true);
     $memSize = $mem['num_seg'] * $mem['seg_size'];
     $memAvailable = $mem['avail_mem'];
     if ($memAvailable > $requiredSpazi) {
         die;
     }
     $start = microtime(true);
     Kwf_Util_MemoryLimit::set(256);
     ini_set('display_errors', 'on');
     set_time_limit(90);
     echo "size: " . round($memSize / (1024 * 1024)) . " MB\n";
     echo "avail: " . round($memAvailable / (1024 * 1024)) . " MB\n";
     echo "\nduration: " . round(microtime(true) - $start, 3) . " s\n";
     $accessTime = array();
     $it = new APCIterator('user', '#^[^-]+\\-[^-]+\\-(\\-cc|procI|url)-#', APC_ITER_KEY | APC_ITER_MEM_SIZE | APC_ITER_ATIME);
     echo "total count: " . $it->getTotalCount() . "\n";
     echo "total hits: " . $it->getTotalHits() . "\n";
     echo "total size: " . round($it->getTotalSize() / (1024 * 1024)) . " MB\n";
     echo "\nduration: " . round(microtime(true) - $start, 3) . " s\n";
     $webs = array();
     foreach ($it as $i) {
         preg_match('#^([^-]+)\\-([^-]+)\\-+([a-zA-Z0-9]+)#', $i['key'], $m);
         $key = $m[1] . '-' . $m[2];
         if (!isset($webs[$key])) {
             $webs[$key] = 0;
         }
         $webs[$key] += $i['mem_size'];
         $accessTime[] = time() - $i['access_time'];
     }
     echo "min lastAccess: " . min($accessTime) . "\n";
     echo "max lastAccess: " . max($accessTime) . "\n";
     echo "avg lastAccess: " . round(array_sum($accessTime) / count($accessTime)) . "\n";
     echo "\nduration: " . round(microtime(true) - $start, 3) . " s\n";
     unset($accessTime);
     echo "\n";
     arsort($webs);
     foreach ($webs as $web => $items) {
         echo "{$web}: " . round($items / $it->getTotalSize() * 100) . "%\n";
     }
     reset($webs);
     $web = key($webs);
     unset($it);
     unset($webs);
     echo "\nduration: " . round(microtime(true) - $start, 3) . " s\n";
     $it = new APCIterator('user', '#^' . preg_quote($web) . '\\-(\\-cc|procI|url)-#', APC_ITER_KEY | APC_ITER_MEM_SIZE | APC_ITER_ATIME);
     echo "\n{$web}\n";
     echo "total count: " . $it->getTotalCount() . "\n";
     echo "total hits: " . $it->getTotalHits() . "\n";
     echo "total size: " . round($it->getTotalSize() / (1024 * 1024)) . " MB\n";
     echo "\nduration: " . round(microtime(true) - $start, 3) . " s\n";
     $accessTime = array();
     $size = array();
     foreach ($it as $i) {
         $t = time() - $i['access_time'];
         $accessTime[$i['key']] = $t;
         $size[$i['key']] = $i['mem_size'];
     }
     unset($it);
     echo "min lastAccess: " . min($accessTime) . "\n";
     echo "max lastAccess: " . max($accessTime) . "\n";
     echo "avg lastAccess: " . round(array_sum($accessTime) / count($accessTime)) . "\n";
     echo "\nduration: " . round(microtime(true) - $start, 3) . " s\n";
     flush();
     arsort($accessTime);
     $deletedBytes = 0;
     $deletedCount = 0;
     foreach ($accessTime as $key => $t) {
         $deletedBytes += $size[$key];
         $memAvailable += $size[$key];
         //echo "delete $key (".round($deletedBytes/(1024*1024))."MB)\n";
         //flush();
         apc_delete($key);
         $deletedCount++;
         if ($memAvailable > $requiredSpazi + 1024 * 1024 * 2) {
             break;
         }
     }
     echo "deleted {$deletedCount} entries\n";
     echo "deleted " . round($deletedBytes / 1024) . " KB\n";
     echo "\nduration: " . round(microtime(true) - $start, 3) . " s\n";
     exit;
 }
コード例 #5
0
ファイル: apc-3.php プロジェクト: jestintab/zendphp
echo "<pre>";
echo "<pre>";
//Example #1 apc_inc() example
echo "Let's do something with success", PHP_EOL;
apc_store('anumber', 42);
echo apc_fetch('anumber'), PHP_EOL;
echo apc_inc('anumber'), PHP_EOL;
echo apc_inc('anumber', 10), PHP_EOL;
echo apc_inc('anumber', 10, $success), PHP_EOL;
var_dump($success);
echo "Now, let's fail", PHP_EOL, PHP_EOL;
apc_store('astring', 'foo');
$ret = apc_inc('astring', 1, $fail);
var_dump($ret);
var_dump($fail);
?>

<?php 
echo "I am here <br/><br/>";
$oApcIt = new APCIterator('user', '/^[a-z]/');
echo "This total APC in mem: [" . $oApcIt->getTotalCount() . "]<br/><br/>";
echo "This total APC hits: [" . $oApcIt->getTotalHits() . "]<br/><br/>";
echo "This total size APC: [" . $oApcIt->getTotalSize() . "]<br/><br/>";
echo "WHILE ";
print_r($oApcIt);
echo "<br/>";
foreach ($oApcIt as $counter) {
    // print_r($counter) . PHP_EOL;
    echo "{$counter['key']}: {$counter['value']}<br/>";
    //apc_dec($counter['key'], $counter['value']) . "<br/>";
}