略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: apc_exists

2024-04-27

apc_exists

(PECL apc >= 3.1.4)

apc_exists检查APC中是否存在某个或者某些key

说明

apc_exists ( mixed $keys ) : mixed

检查是否有一个或者多个APC键名存在

参数

keys

string,或者包含键的 array,元素是字符串。

返回值

如果Key存在的话返回 TRUE , 否则返回 FALSE 如果参数 keys是一个array , 将返回一个包含所有存在的key的数组,假如数组中的key一个都不存在的话, 就返回空的数组。

范例

Example #1 apc_exists() 例子

<?php
$fruit  
'apple';
$veggie 'carrot';

apc_store('foo'$fruit);
apc_store('bar'$veggie);

if (
apc_exists('foo')) {
    echo 
"Foo exists: ";
    echo 
apc_fetch('foo');
} else {
    echo 
"Foo does not exist";
}

echo 
PHP_EOL;
if (
apc_exists('baz')) {
    echo 
"Baz exists.";
} else {
    echo 
"Baz does not exist";
}

echo 
PHP_EOL;

$ret apc_exists(array('foo''donotexist''bar'));
var_dump($ret);

?>

以上例程的输出类似于:

Foo exists: apple
Baz does not exist
array(2) {
  ["foo"]=>
  bool(true)
  ["bar"]=>
  bool(true)
}

参见

  • apc_cache_info() - Retrieves cached information from APC's data store
  • apc_fetch() - 从缓存中取出存储的变量
add a noteadd a note

User Contributed Notes 1 note

up
1
FiFFiO
7 years ago
apc_exists declaration if your PECL apc version is less than 3.1.4:

<?php
if(!function_exists('apc_exists'))
    {
    function
apc_exists($keys)
        {
       
$result;
       
apc_fetch($keys, $result);
        return
$result;
        }
    }
?>

官方地址:https://www.php.net/manual/en/function.apc-exists.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3