This is one stop global knowledge base where you can learn about all the products, solutions and support features.
(PECL apcu >= 4.0.0)
apcu_exists — Checks if entry exists
apcu_exists(mixed $keys): mixed
Checks if one or more APCu entries exist.
keys
A string , or an array of strings, that contain keys.
Returns
true
if the key exists, otherwise
false
Or if an
array
was passed to
keys
, then an array is returned that contains all existing keys, or an empty array if none exist.
Example #1 apcu_exists() example
<?php
$fruit = 'apple';
$veggie = 'carrot';
apcu_store('foo', $fruit);
apcu_store('bar', $veggie);
if (apcu_exists('foo')) {
echo "Foo exists: ";
echo apcu_fetch('foo');
} else {
echo "Foo does not exist";
}
echo PHP_EOL;
if (apcu_exists('baz')) {
echo "Baz exists.";
} else {
echo "Baz does not exist";
}
echo PHP_EOL;
$ret = apcu_exists(array('foo', 'donotexist', 'bar'));
var_dump($ret);
?>
The above example will output something similar to:
Foo exists: apple Baz does not exist array(2) { ["foo"]=> bool(true) ["bar"]=> bool(true) }
(PECL apcu >= 4.0.0)
apcu_fetch — Fetch a stored variable from the cache
apcu_fetch(mixed $key, bool &$success = ?): mixed
Fetches an entry from the cache.
key
The
key
used to store the value (with
apcu_store()
). If an array is passed then each element is fetched and returned.
success
Set to
true
in success and
false
in failure.
The stored variable or array of variables on success;
false
on failure
Version | Description |
---|---|
PECL apcu 3.0.17 |
The
success
parameter was added.
|
Example #1 A apcu_fetch() example
<?php
$bar = 'BAR';
apcu_store('foo', $bar);
var_dump(apcu_fetch('foo'));
?>
The above example will output:
string(3) "BAR"
(PECL apcu >= 4.0.0)
apcu_inc — Increase a stored number
apcu_inc( string $key, int $step = 1, bool &$success = ?, int $ttl = 0 ): int|false
Increases a stored number.
key
The key of the value being increased.
step
The step, or value to increase.
success
Optionally pass the success or fail boolean value to this referenced variable.
ttl
TTL to use if the operation inserts a new value (rather than incrementing an existing one).
Returns the current value of
key
's value on success, or
false
on failure
Example #1 apcu_inc() example
<?php
echo "Let's do something with success", PHP_EOL;
apcu_store('anumber', 42);
echo apcu_fetch('anumber'), PHP_EOL;
echo apcu_inc('anumber'), PHP_EOL;
echo apcu_inc('anumber', 10), PHP_EOL;
echo apcu_inc('anumber', 10, $success), PHP_EOL;
var_dump($success);
echo "Now, let's fail", PHP_EOL, PHP_EOL;
apcu_store('astring', 'foo');
$ret = apcu_inc('astring', 1, $fail);
var_dump($ret);
var_dump($fail);
?>
The above example will output something similar to:
Let's do something with success 42 43 53 63 bool(true) Now, let's fail bool(false) bool(false)
(No version information available, might only be in Git)
apcu_key_info — Get detailed information about the cache key
apcu_key_info(string $key): ?array
Get detailed information about the cache key
key
Get detailed information about the cache key
An array containing the detailed information about the cache key, or
null
if the key does not exist.
Example #1 A apcu_key_info() example
<?php
apcu_add('a','b');
var_dump(apcu_key_info('a'));
?>
The above example will output:
array(7) { ["hits"]=> int(0) ["access_time"]=> int(1606701783) ["mtime"]=> int(1606701783) ["creation_time"]=> int(1606701783) ["deletion_time"]=> int(0) ["ttl"]=> int(0) ["refs"]=> int(0) }
(PECL apcu >= 4.0.0)
apcu_sma_info — Retrieves APCu Shared Memory Allocation information
apcu_sma_info(bool $limited = false): array|false
Retrieves APCu Shared Memory Allocation information.
limited
When set to
false
(default)
apcu_sma_info()
will return a detailed information about each segment.
Array of Shared Memory Allocation data;
false
on failure.
Example #1 A apcu_sma_info() example
<?php
print_r(apcu_sma_info());
?>
The above example will output something similar to:
Array ( [num_seg] => 1 [seg_size] => 31457280 [avail_mem] => 31448408 [block_lists] => Array ( [0] => Array ( [0] => Array ( [size] => 31448408 [offset] => 8864 ) ) ) )
(PECL apcu >= 4.0.0)
apcu_store — Cache a variable in the data store
apcu_store(string $key, mixed $var, int $ttl = 0): bool
apcu_store(array $values, mixed $unused = NULL, int $ttl = 0): array
Cache a variable in the data store.
Note : Unlike many other mechanisms in PHP, variables stored using apcu_store() will persist between requests (until the value is removed from the cache).
key
Store the variable using this name.
key
s are cache-unique, so storing a second value with the same
key
will overwrite the original value.
var
The variable to store
ttl
Time To Live; store
var
in the cache for
ttl
seconds. After the
ttl
has passed, the stored variable will be expunged from the cache (on the next request). If no
ttl
is supplied (or if the
ttl
is
0
), the value will persist until it is removed from the cache manually, or otherwise fails to exist in the cache (clear, restart, etc.).
values
Names in key, variables in value.
Returns
true
on success or
false
on failure. Second syntax returns array with error keys.
Example #1 A apcu_store() example
<?php
$bar = 'BAR';
apcu_store('foo', $bar);
var_dump(apcu_fetch('foo'));
?>
The above example will output:
string(3) "BAR"