diff --git a/apc_arginfo.h b/apc_arginfo.h index 0bd61c96..dd20c3af 100644 --- a/apc_arginfo.h +++ b/apc_arginfo.h @@ -71,6 +71,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_apcu_exists, 0) ZEND_ARG_INFO(0, keys) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_apcu_exists_any, 1) + ZEND_ARG_INFO(0, keys) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_entry, 0, 0, 2) ZEND_ARG_INFO(0, key) ZEND_ARG_TYPE_INFO(0, generator, IS_CALLABLE, 0) diff --git a/php_apc.c b/php_apc.c index 65863a1c..397312dc 100644 --- a/php_apc.c +++ b/php_apc.c @@ -70,6 +70,7 @@ PHP_FUNCTION(apcu_inc); PHP_FUNCTION(apcu_dec); PHP_FUNCTION(apcu_cas); PHP_FUNCTION(apcu_exists); +PHP_FUNCTION(apcu_exists_any); /* }}} */ /* {{{ ZEND_DECLARE_MODULE_GLOBALS(apcu) */ @@ -712,6 +713,40 @@ PHP_FUNCTION(apcu_exists) { } /* }}} */ +/* {{{ proto mixed apcu_exists_any(array keys) + */ +PHP_FUNCTION(apcu_exists_any) { + zval *key; + time_t t; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) == FAILURE) { + RETURN_FALSE; + } + + t = apc_time(); + + if (Z_TYPE_P(key) != IS_ARRAY) { + apc_warning("apcu_exists_any() expects an array of strings."); + RETURN_FALSE; + } + + zval *hentry=NULL; + + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(key), hentry) { + ZVAL_DEREF(hentry); + if (Z_TYPE_P(hentry) == IS_STRING) { + if (apc_cache_exists(apc_user_cache, Z_STR_P(hentry), t)) { + RETURN_TRUE; + } + } else { + apc_warning("apcu_exists_any() expects an array of strings."); + } + } ZEND_HASH_FOREACH_END(); + + RETURN_FALSE; +} +/* }}} */ + /* {{{ proto mixed apcu_delete(mixed keys) */ PHP_FUNCTION(apcu_delete) { @@ -798,6 +833,7 @@ zend_function_entry apcu_functions[] = { PHP_FE(apcu_dec, arginfo_apcu_inc) PHP_FE(apcu_cas, arginfo_apcu_cas) PHP_FE(apcu_exists, arginfo_apcu_exists) + PHP_FE(apcu_exists_any, arginfo_apcu_exists_any) PHP_FE(apcu_entry, arginfo_apcu_entry) #ifdef APC_DEBUG PHP_FE(apcu_inc_request_time, NULL) diff --git a/php_apc.h b/php_apc.h index b7e97d77..163657fb 100644 --- a/php_apc.h +++ b/php_apc.h @@ -39,6 +39,7 @@ PHP_APCU_API PHP_FUNCTION(apcu_add); PHP_APCU_API PHP_FUNCTION(apcu_delete); PHP_APCU_API PHP_FUNCTION(apcu_exists); +PHP_APCU_API PHP_FUNCTION(apcu_exists_any); PHP_APCU_API PHP_FUNCTION(apcu_fetch); PHP_APCU_API PHP_FUNCTION(apcu_store); PHP_APCU_API PHP_FUNCTION(apcu_inc); diff --git a/tests/apc_013_exists_any.phpt b/tests/apc_013_exists_any.phpt new file mode 100644 index 00000000..254ffd17 --- /dev/null +++ b/tests/apc_013_exists_any.phpt @@ -0,0 +1,24 @@ +--TEST-- +APC: apcu_exists_any +--SKIPIF-- + +--INI-- +apc.enabled=1 +apc.enable_cli=1 +--FILE-- + +===DONE=== +--EXPECT-- +bool(false) +bool(true) +bool(false) +bool(true) +===DONE===