apcu_sma_info example


    public function getConfigCacheInfo()
    {
        $backendCache = $this->cache->getBackend();

        if ($backendCache instanceof Zend_Cache_Backend_Apcu) {
            $info = [];
            $apcInfo = apcu_cache_info('user');
            $info['files'] = $apcInfo['num_entries'];
            $info['size'] = $this->encodeSize($apcInfo['mem_size']);
            $apcInfo = apcu_sma_info();
            $info['freeSpace'] = $this->encodeSize($apcInfo['avail_mem']);
        } elseif ($backendCache instanceof Zend_Cache_Backend_Redis) {
            $info = [];

            /** @var Redis $redis */
            $redis = $backendCache->getRedis();
            $info['files'] = $redis->dbSize();
            $info['size'] = $this->encodeSize($redis->info()['used_memory']);
        } else {
            $dir = null;

            
return false;
    }

    /** * Return the filling percentage of the backend storage * * @throws Zend_Cache_Exception * @return int integer between 0 and 100 */
    public function getFillingPercentage()
    {
        $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 apcu memory size');
        }
        if ($memUsed > $memSize) {
            return 100;
        }
        return ((int) (100. * ($memUsed / $memSize)));
    }

    
Home | Imprint | This part of the site doesn't use cookies.