Skip to content

Commit 56171da

Browse files
committed
Fixed bug fetch only fetched one result
1 parent 4d9fda9 commit 56171da

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

php_memcached.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static zend_bool s_invoke_cache_callback(zval *zobject, zend_fcall_info *fci, ze
382382
typedef zend_bool (*php_memc_result_apply_fn)(php_memc_object_t *intern, zend_string *key, zval *value, zval *cas, uint32_t flags, void *context);
383383

384384
static
385-
memcached_return php_memc_result_apply(php_memc_object_t *intern, php_memc_result_apply_fn result_apply_fn, void *context);
385+
memcached_return php_memc_result_apply(php_memc_object_t *intern, php_memc_result_apply_fn result_apply_fn, zend_bool fetch_delay, void *context);
386386

387387
static
388388
zend_bool php_memc_mget_apply(php_memc_object_t *intern, zend_string *server_key,
@@ -579,7 +579,7 @@ uint64_t s_zval_to_uint64 (zval *cas)
579579
****************************************/
580580

581581
static
582-
memcached_return php_memc_result_apply(php_memc_object_t *intern, php_memc_result_apply_fn result_apply_fn, void *context)
582+
memcached_return php_memc_result_apply(php_memc_object_t *intern, php_memc_result_apply_fn result_apply_fn, zend_bool fetch_delay, void *context)
583583
{
584584
memcached_result_st result, *result_ptr;
585585
memcached_return rc, status = MEMCACHED_SUCCESS;
@@ -599,7 +599,7 @@ memcached_return php_memc_result_apply(php_memc_object_t *intern, php_memc_resul
599599
}
600600
else {
601601
zend_string *key;
602-
zval zv_value, zv_cas;
602+
zval val, zcas;
603603
zend_bool retval;
604604

605605
uint64_t cas;
@@ -608,7 +608,7 @@ memcached_return php_memc_result_apply(php_memc_object_t *intern, php_memc_resul
608608
const char *res_key;
609609
size_t res_key_len;
610610

611-
if (!s_memcached_result_to_zval(intern->memc, &result, &zv_value)) {
611+
if (!s_memcached_result_to_zval(intern->memc, &result, &val)) {
612612
if (EG(exception)) {
613613
status = MEMC_RES_PAYLOAD_FAILURE;
614614
memcached_quit(intern->memc);
@@ -623,19 +623,21 @@ memcached_return php_memc_result_apply(php_memc_object_t *intern, php_memc_resul
623623
cas = memcached_result_cas(&result);
624624
flags = memcached_result_flags(&result);
625625

626-
s_uint64_to_zval(&zv_cas, cas);
626+
s_uint64_to_zval(&zcas, cas);
627627

628628
key = zend_string_init (res_key, res_key_len, 0);
629-
retval = result_apply_fn(intern, key, &zv_value, &zv_cas, flags, context);
629+
retval = result_apply_fn(intern, key, &val, &zcas, flags, context);
630630

631-
zend_string_release (key);
632-
zval_ptr_dtor(&zv_value);
633-
zval_ptr_dtor(&zv_cas);
631+
zend_string_release(key);
632+
zval_ptr_dtor(&val);
633+
zval_ptr_dtor(&zcas);
634634

635635
/* Stop iterating on false */
636636
if (!retval) {
637-
/* Make sure we clear our results */
638-
while (memcached_fetch_result(intern->memc, &result, &rc)) {}
637+
if (!fetch_delay) {
638+
/* Make sure we clear our results */
639+
while (memcached_fetch_result(intern->memc, &result, &rc)) {}
640+
}
639641
break;
640642
}
641643
}
@@ -692,7 +694,7 @@ zend_bool php_memc_mget_apply(php_memc_object_t *intern, zend_string *server_key
692694
return 1;
693695
}
694696

695-
status = php_memc_result_apply(intern, result_apply_fn, context);
697+
status = php_memc_result_apply(intern, result_apply_fn, 0, context);
696698

697699
if (s_memc_status_handle_result_code(intern, status) == FAILURE) {
698700
return 0;
@@ -1543,8 +1545,11 @@ void s_create_result_array(zend_string *key, zval *value, zval *cas, uint32_t fl
15431545
add_assoc_str_ex(return_value, ZEND_STRL("key"), zend_string_copy(key));
15441546
add_assoc_zval_ex(return_value, ZEND_STRL("value"), value);
15451547

1546-
add_assoc_zval_ex(return_value, ZEND_STRL("cas"), cas);
1547-
add_assoc_long_ex(return_value, ZEND_STRL("flags"), MEMC_VAL_GET_USER_FLAGS(flags));
1548+
if (Z_LVAL_P(cas)) {
1549+
/* BC compatible */
1550+
add_assoc_zval_ex(return_value, ZEND_STRL("cas"), cas);
1551+
add_assoc_long_ex(return_value, ZEND_STRL("flags"), MEMC_VAL_GET_USER_FLAGS(flags));
1552+
}
15481553
}
15491554

15501555
static
@@ -1648,7 +1653,7 @@ PHP_METHOD(Memcached, fetch)
16481653
s_memc_set_status(intern, MEMCACHED_SUCCESS, 0);
16491654

16501655
array_init(return_value);
1651-
status = php_memc_result_apply(intern, s_fetch_apply, return_value);
1656+
status = php_memc_result_apply(intern, s_fetch_apply, 1, return_value);
16521657

16531658
if (s_memc_status_handle_result_code(intern, status) == FAILURE) {
16541659
zval_ptr_dtor(return_value);
@@ -1685,7 +1690,7 @@ PHP_METHOD(Memcached, fetchAll)
16851690
s_memc_set_status(intern, MEMCACHED_SUCCESS, 0);
16861691

16871692
array_init(return_value);
1688-
status = php_memc_result_apply(intern, s_fetch_all_apply, return_value);
1693+
status = php_memc_result_apply(intern, s_fetch_all_apply, 0, return_value);
16891694

16901695
if (s_memc_status_handle_result_code(intern, status) == FAILURE) {
16911696
zval_dtor(return_value);

0 commit comments

Comments
 (0)