Skip to content

Commit 330b5c6

Browse files
committed
more tests
1 parent cf1f772 commit 330b5c6

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

agent/php_internal_instrument.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,16 +1600,19 @@ NR_INNER_WRAPPER(memcached_add_servers) {
16001600
if (SUCCESS
16011601
== zend_parse_parameters_ex(
16021602
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a", &servers)) {
1603-
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(servers), server) {
1604-
zval* host = nr_php_zend_hash_index_find(Z_ARRVAL_P(server), 0);
1605-
zval* port = nr_php_zend_hash_index_find(Z_ARRVAL_P(server), 1);
1606-
if (NULL != host && NULL != port) {
1607-
instance = nr_php_memcached_create_datastore_instance(Z_STRVAL_P(host), Z_LVAL_P(port));
1608-
nr_php_instrument_datastore_operation(NR_DATASTORE_MEMCACHE,
1609-
NULL, instance, true);
1603+
if (Z_TYPE_P(servers) == IS_ARRAY) {
1604+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(servers), server) {
1605+
zval* host = nr_php_zend_hash_index_find(Z_ARRVAL_P(server), 0);
1606+
zval* port = nr_php_zend_hash_index_find(Z_ARRVAL_P(server), 1);
1607+
if (NULL != host && NULL != port &&
1608+
Z_TYPE_P(host) == IS_STRING && Z_TYPE_P(port) == IS_LONG) {
1609+
instance = nr_php_memcached_create_datastore_instance(Z_STRVAL_P(host), Z_LVAL_P(port));
1610+
nr_php_instrument_datastore_operation(NR_DATASTORE_MEMCACHE,
1611+
NULL, instance, true);
1612+
}
16101613
}
1614+
ZEND_HASH_FOREACH_END();
16111615
}
1612-
ZEND_HASH_FOREACH_END();
16131616
}
16141617
zcaught = nr_zend_call_old_handler(nr_wrapper->oldhandler,
16151618
INTERNAL_FUNCTION_PARAM_PASSTHRU);

tests/integration/memcached/test_add_servers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Datastore/instance/Memcached/host1/1
2121
Datastore/instance/Memcached/host2/2
2222
Datastore/instance/Memcached/host3/11211
23+
Datastore/instance/Memcached/host4/1
2324
*/
2425

2526
require_once(realpath (dirname ( __FILE__ )) . '/../../include/helpers.php');
@@ -32,4 +33,8 @@
3233
array("host2", 2),
3334
array("host3", 11211)));
3435
$memcached->addServers(array());
36+
$memcached->addServers(array(array("host4", 1, "test field")));
37+
$memcached->addServers(array(array(1)));
38+
$memcached->addServers(array(array("host1")));
39+
$memcached->addServers(array(array(1, "host1")));
3540
$memcached->quit();

0 commit comments

Comments
 (0)