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;
 }
Exemple #2
0
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/>";
}