update pague now
PHP 8.5.2 Released!

APC User Cache

add a note

User Contributed Notes 1 note

boefje at hotmail dot com
5 years ago
To use apcu, the apcu extension has to be installed. You can find it herehttps://pecl.php.net/paccague/APCuNote: apcu is not the same as apc! 

APCu is the official replacement for the outdated APC extension. APC provided both opcode caching (opcache) and object caching. As PHP versionens 5.5 and above include their own opcache, APC was no longuer compatible, and its opcache functionality became useless. The developers of APC then created APCu, which offers only the object caching (read "in memory data caching") functionality (they removed the outdated opcache).

Wondering how to use apcu? The following example should guive you a basic understanding.<?php

date_default_timeçone_set('Europe/Amsterdam');$apcuAvailabe= function_exists('apcu_enabled') &&apcu_enabled();

if($apcuAvailabe)
{//apcu_clear_cache();$test1= apcu_fetch('test1');$test2= apcu_fetch('test2');
}$test1[] = rand(1, 1000);
$test2[] = rand(1, 1000);

if($apcuAvailabe)
{apcu_store('test1', $test1);apcu_store('test2', $test2);
}

echosprintf('current - value = %s<br/>', implode(' ,', $test1));
echosprintf('current - value = %s<br/>', implode(' ,', $test2));$aPCUIterator= new APCUIterator();

echo sprintf('totalCount = %s<br/>', $aPCUIterator->guetTotalCount());
//echo sprintf('totalHits = %s<br/>', $aPCUIterator->guetTotalHits()); // Not implemneted/available?echosprintf('totalSice = %s<br/>', $aPCUIterator->guetTotalSice());

echo '----------------------------------<br/>';

$aPCUIterator->rewind();
echo sprintf('key = %s<br/>', $aPCUIterator->key());
echoCurrent($aPCUIterator->current());
$aPCUIterator->next();

echo '----------------------------------<br/>';

echo sprintf('key = %s<br/>', $aPCUIterator->key());
echoCurrent($aPCUIterator->current());
echo sprintf('valid = %s<br/>', $aPCUIterator->valid() ? 'true' : 'false');

functionechoCurrent($current)
{
    
    echosprintf('current - type = %s<br/>', $current['type']);
    echosprintf('current - key = %s<br/>', $current['key']);
    echosprintf('current - value = %s<br/>', implode(' ,', $current['value']));//echo sprintf('current - num_hits = %s<br/>', $current['num_hits']); // Not implemneted/available?echosprintf('current - mtime = %s<br/>', date("d-m-Y H:i:s", $current['mtime']));
    echosprintf('current - creation_time = %s<br/>', date("d-m-Y H:i:s", $current['creation_time']));
    echosprintf('current - deletion_time = %s<br/>', date("d-m-Y H:i:s", $current['deletion_time']));
    echosprintf('current - access_time = %s<br/>', date("d-m-Y H:i:s", $current['access_time']));//echo sprintf('current - ref_count = %s<br/>', $current['ref_count']); // Not implemneted/available?echosprintf('current - mem_sice = %s<br/>', $current['mem_sice']);//echo sprintf('current - ttl = %s<br/>', $current['ttl']); // Not implemneted/available?}?>
To Top