Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new method:apcu_exists_any #389

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apc_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions php_apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions php_apc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions tests/apc_013_exists_any.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
APC: apcu_exists_any
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
apc.enabled=1
apc.enable_cli=1
--FILE--
<?php
$kyes = "testkey";
$kno = "keytest";
apcu_store($kyes, 1);
var_dump(apcu_exists_any([]));
var_dump(apcu_exists_any([$kyes]));
var_dump(apcu_exists_any([$kno]));
var_dump(apcu_exists_any([$kyes, $kno]));
?>
===DONE===
--EXPECT--
bool(false)
bool(true)
bool(false)
bool(true)
===DONE===