您的位置:首页 > 编程语言 > PHP开发

zookeeper的php扩展安装及使用

2015-09-29 08:43 806 查看
一、安装libzookeeper

cd /usr/local/src/
wget http://mirror.bit.edu.cn/apache//zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz
tar -xf zookeeper-3.4.5.tar.gz
cd zookeeper-3.4.5/src/c
./configure –prefix=/usr/local/zookeeper/zookeeper-3.4.5/
make && make install
二、安装php zookeeper扩展

cd /usr/local/src/
wget ‘http://pecl.php.net/get/zookeeper-0.2.2.tgz’
tar zxvf zookeeper-0.2.2.tgz
cd zookeeper-0.2.2
phpize
./configure –with-php-config=/usr/local/php/bin/php-config  –with-libzookeeper-dir=/usr/local/zookeeper/zookeeper-3.4.5/
make && make install
vim /usr/local/php/etc/php.ini
查找:extension_dir=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/”
添加:extension=zookeeper.so
三注意:php-config libzookeeper-di路径一定要正确

三、扩展的使用

// 获取单条配置
$path      = '/' . trim($path, '/');
$zookeeper = new \Zookeeper('address:2181');
if ($zookeeper->exists($path)) {
$value = $zookeeper->get($path);
}

//创建节点
if (!$zookeeper->exists($path)) {
$zookeeper->create($path, $value, array(array(
'perms' => 31,
'scheme' => 'world',
'id' => 'anyone'
)));
}

//更新节点
if ($zookeeper->exists($path)) {
$zookeeper->set($path, $value);
}

//删除一个节点
if ($zookeeper->exists($path)) {
$zookeeper->delete($path);
}

//获取所有子节点名称
if ($zookeeper->exists($path)) {
$value = $zookeeper->getChildren($path);
}

//获取acl
if ($zookeeper->exists($path)) {
$zookeeper->getAcl($path);
}

//设置acl
if ($zookeeper->exists($path)) {
$acl     = $zookeeper->getAcl($path);
$version = isset($acl['0']['aversion']) ? $acl['0']['aversion'] : 0;
$zookeeper->setAcl($path, $version, array(array(
'perms' => 31,
'scheme' => 'world',
'id' => 'anyone'
)));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: