@@ -1302,6 +1302,71 @@ PHP_METHOD(Memcached, addServer)
1302
1302
}
1303
1303
/* }}} */
1304
1304
1305
+ /* {{{ Memcached::addServers(array servers)
1306
+ Adds the given memcache servers to the server list */
1307
+ PHP_METHOD (Memcached , addServers )
1308
+ {
1309
+ zval * servers ;
1310
+ zval * * entry ;
1311
+ zval * * z_host , * * z_port , * * z_weight = NULL ;
1312
+ uint32_t weight = 0 ;
1313
+ int entry_size , i = 0 ;
1314
+ memcached_server_st * list = NULL ;
1315
+ memcached_return status ;
1316
+ MEMC_METHOD_INIT_VARS ;
1317
+
1318
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "a/" , & servers ) == FAILURE ) {
1319
+ return ;
1320
+ }
1321
+
1322
+ MEMC_METHOD_FETCH_OBJECT ;
1323
+ MEMC_G (rescode ) = MEMCACHED_SUCCESS ;
1324
+
1325
+ for (zend_hash_internal_pointer_reset (Z_ARRVAL_P (servers )), i = 0 ;
1326
+ zend_hash_get_current_data (Z_ARRVAL_P (servers ), (void * * )& entry ) == SUCCESS ;
1327
+ zend_hash_move_forward (Z_ARRVAL_P (servers )), i ++ ) {
1328
+
1329
+ if (Z_TYPE_PP (entry ) != IS_ARRAY ) {
1330
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "server list entry #%d is not an array" , i + 1 );
1331
+ continue ;
1332
+ }
1333
+
1334
+ entry_size = zend_hash_num_elements (Z_ARRVAL_PP (entry ));
1335
+
1336
+ if (entry_size > 1 ) {
1337
+ zend_hash_index_find (Z_ARRVAL_PP (entry ), 0 , (void * * )& z_host );
1338
+ zend_hash_index_find (Z_ARRVAL_PP (entry ), 1 , (void * * )& z_port );
1339
+ convert_to_string_ex (z_host );
1340
+ convert_to_long_ex (z_port );
1341
+
1342
+ weight = 0 ;
1343
+ if (entry_size > 2 ) {
1344
+ zend_hash_index_find (Z_ARRVAL_PP (entry ), 2 , (void * * )& z_weight );
1345
+ convert_to_long_ex (z_weight );
1346
+ weight = Z_LVAL_PP (z_weight );
1347
+ }
1348
+
1349
+ list = memcached_server_list_append_with_weight (list , Z_STRVAL_PP (z_host ),
1350
+ Z_LVAL_PP (z_port ), weight , & status );
1351
+
1352
+ if (php_memc_handle_error (status TSRMLS_CC ) == 0 ) {
1353
+ continue ;
1354
+ }
1355
+ }
1356
+
1357
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "could not add entry #%d to the server list" , i + 1 );
1358
+ }
1359
+
1360
+ status = memcached_server_push (i_obj -> memc , list );
1361
+ memcached_server_list_free (list );
1362
+ if (php_memc_handle_error (status TSRMLS_CC ) < 0 ) {
1363
+ RETURN_FALSE ;
1364
+ }
1365
+
1366
+ RETURN_TRUE ;
1367
+ }
1368
+ /* }}} */
1369
+
1305
1370
/* {{{ Memcached::getServerList()
1306
1371
Returns the list of the memcache servers in use */
1307
1372
PHP_METHOD (Memcached , getServerList )
@@ -2362,6 +2427,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_addServer, 0, 0, 2)
2362
2427
ZEND_ARG_INFO (0 , weight )
2363
2428
ZEND_END_ARG_INFO ()
2364
2429
2430
+ static
2431
+ ZEND_BEGIN_ARG_INFO (arginfo_addServers , 0 )
2432
+ ZEND_ARG_ARRAY_INFO (0 , servers , 0 )
2433
+ ZEND_END_ARG_INFO ()
2434
+
2365
2435
static
2366
2436
ZEND_BEGIN_ARG_INFO (arginfo_getServerList , 0 )
2367
2437
ZEND_END_ARG_INFO ()
@@ -2425,6 +2495,7 @@ static zend_function_entry memcached_class_methods[] = {
2425
2495
MEMC_ME (decrement , arginfo_decrement )
2426
2496
2427
2497
MEMC_ME (addServer , arginfo_addServer )
2498
+ MEMC_ME (addServers , arginfo_addServers )
2428
2499
MEMC_ME (getServerList , arginfo_getServerList )
2429
2500
MEMC_ME (getServerByKey , arginfo_getServerByKey )
2430
2501
0 commit comments