@@ -1395,14 +1395,32 @@ PHP_METHOD(Memcached, addServers)
1395
1395
entry_size = zend_hash_num_elements (Z_ARRVAL_PP (entry ));
1396
1396
1397
1397
if (entry_size > 1 ) {
1398
- zend_hash_index_find (Z_ARRVAL_PP (entry ), 0 , (void * * )& z_host );
1399
- zend_hash_index_find (Z_ARRVAL_PP (entry ), 1 , (void * * )& z_port );
1398
+ zend_hash_internal_pointer_reset (Z_ARRVAL_PP (entry ));
1399
+
1400
+ /* Check that we have a host */
1401
+ if (zend_hash_get_current_data (Z_ARRVAL_PP (entry ), (void * * )& z_host ) == FAILURE ) {
1402
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "could not get server host for entry #%d" , i + 1 );
1403
+ continue ;
1404
+ }
1405
+
1406
+ /* Check that we have a port */
1407
+ if (zend_hash_move_forward (Z_ARRVAL_PP (entry )) == FAILURE ||
1408
+ zend_hash_get_current_data (Z_ARRVAL_PP (entry ), (void * * )& z_port ) == FAILURE ) {
1409
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "could not get server port for entry #%d" , i + 1 );
1410
+ continue ;
1411
+ }
1412
+
1400
1413
convert_to_string_ex (z_host );
1401
1414
convert_to_long_ex (z_port );
1402
1415
1403
1416
weight = 0 ;
1404
1417
if (entry_size > 2 ) {
1405
- zend_hash_index_find (Z_ARRVAL_PP (entry ), 2 , (void * * )& z_weight );
1418
+ /* Try to get weight */
1419
+ if (zend_hash_move_forward (Z_ARRVAL_PP (entry )) == FAILURE ||
1420
+ zend_hash_get_current_data (Z_ARRVAL_PP (entry ), (void * * )& z_weight ) == FAILURE ) {
1421
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "could not get server weight for entry #%d" , i + 1 );
1422
+ }
1423
+
1406
1424
convert_to_long_ex (z_weight );
1407
1425
weight = Z_LVAL_PP (z_weight );
1408
1426
}
@@ -1568,7 +1586,6 @@ PHP_METHOD(Memcached, getStats)
1568
1586
}
1569
1587
/* }}} */
1570
1588
1571
-
1572
1589
/* {{{ Memcached::getVersion()
1573
1590
Returns the version of each memcached server in the pool */
1574
1591
PHP_METHOD (Memcached , getVersion )
0 commit comments