QConf 管理端接口(PHP) - Qihoo360/QConf GitHub Wiki
使用
- 安装QConf管理端的c++库
进入manager目录,通过以下命令构建:
mkdir build && cd build
cmake ..
make
make install
默认的安装目录为 /usr/local/qconf/manage
使用如下配置可以指定安装目录:
cmake .. -DCMAKE_INSTALL_PREFIX=/install/prefix
- 编译并安装qconf manager的php扩展
phpize
./configure
--with-php-config=${php-config 命令}
--with-qconfzk-dir=${qconf 安装目录}/manage/include
--enable-static
LDFLAGS=${qconf 安装目录}/manage/lib/libqconf_zk.a
make
make install
接口说明
构造函数
QConfZK($zoo_host);
Parameters
zoo_host - Zookeeper location,comma separated host:port pairs, each corresponding to a zk server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
Example
$qzk = new QConfZK($zoo_host);
配置相关函数
nodeGet($path)
nodeSet($path, $value)
nodeDelete($path)
Parameters
path - key of configuration.
value - value of the new configuration
Return Value
nodeGet return value of the configuation, NULL if failed
nodeDelete and node Set return 0 if success, othres if failed
Example
$qzk = new QConfZK("127.0.0.1:2181");
$qzk->nodeSet("/demo/config", "value");
$value = $qzk->nodeGet("/demo/config");
echo $value . PHP_EOL;
$qzk->nodeDelete("/demo/config");
服务配置相关函数
servicesGet($path)
servicesGetWithStatus($path)
servicesSet($path, $array_services)
serviceAdd($path, $service, $statu)
serviceDelete($path, $service)
serviceUp($path, $service)
serviceOffline($path, $service)
serviceDown($path, $service)
serviceClear($path)
Parameters
path - key of service configuration.
service - service ip:port
status - the services status, can be one of QCONF_STATUS_UP, QCONF_STATUS_DOWN, QCONF_STATUS_OFFLINE
array_services - new service array of ip:port and status pair
Return Value
servicesGet return array of service ip:port, NULL if failed
servicesGetWithStatus return array of service ip:port and status pair
other function return 0 if success
Example
<?php
$qzk = new QConfZK("127.0.0.1:2181");
$service_path = "/demo/services";
$services_input = array("1.1.1.1:80" => QCONF_STATUS_UP, "1.1.1.2:80" => QCONF_STATUS_DOWN);
$qzk->servicesSet($service_path, $services_input);
$services_output = $qzk->servicesGetWithStatus($service_path);
$services_output_k = $qzk->servicesGet($service_path);
var_dump($services_output);
var_dump($services_output_k);
$qzk->serviceAdd($service_path, "1.1.1.3:80", QCONF_STATUS_UP);
$qzk->serviceOffline($service_path, "1.1.1.3:80");
$qzk->serviceDown($service_path, "1.1.1.3:80");
$qzk->serviceUp($service_path, "1.1.1.3:80");
$qzk->serviceDelete($service_path, "1.1.1.1:3:80");
$qzk->serviceClear($service_path);
?>
子配置相关函数
list($path)
listWithValue($path)
Parameters
path - key of configuration.
Return Value
list return array of all children config key, NULL if failed
listWithValue return array of all children config key together its value, NULL if failed
Example
$qzk = new QConfZK("127.0.0.1:2181");
var_dump($qzk->list("/demo"));
var_dump($qzk->listWithValue("/demo"));
灰度功能相关
grayBegin($array_key, $array_machine)
grayRollback($gray_id)
grayCommit($gray_id)
Parameters
array_key - array of all key value pair, which need to be in gray process
array_machine - array of gray machine hostname
gray_id - return value of grayBegin
Return Value
grayBegin return gray_id, the unique id of current gray process
grayRollback and grayCommit 0 if success
Example
$machines = array($hostname);
$nodes = array("/demo/gray1" => "value1", "/demo/gray2" => "value2");
$gray_id = $qzk->grayBegin($nodes, $machines);
assert(0 === $qzk->grayCommit($gray_id));
//assert(0 === $qzk->grayRollback($gray_id));