php-zookeeper扩展安装

zookeeper安装

zookeeper中有一个C客户端为PHP-Zookeeper提供类库。

安装PHP-Zookeeper类库

zookeeper安装目录: /appServer/zookeeper-3.4.9

# /appServer/zookeeper-3.4.9/src/c
# ./configure
# make && make instal

安装php的zookeeper扩展

php目录:/appServer/php5.6
pecl地址:http://pecl.php.net/package/zookeeper

# wget http://pecl.php.net/get/zookeeper-0.4.0.tgz
# tar zxvf zookeeper-0.4.0.tgz
# cd zookeeper-0.4.0
# /appServer/php5.6/bin/phpize
# ./configure --with-php-config=/appServer/php5.6/bin/php-config --with-libzookeeper-dir
# make && make install
# vim php.ini
# extension=zookeeper.so

查看是否加载成功

# /appServer/php5.6/bin/php -m | grep zookeeper
zookeeper

程序测试:

$ cat test.php
<?php
$zc = new Zookeeper();
$zc->connect('localhost:2181');
//尝试查询节点数据
var_dump($zc->get('/server_host'));

$ /appServer/php5.6/bin/php -f test.php 
string(32) "这是一个测试数据,哈哈!"

到此结束!

    原文作者:战神悟空
    原文地址: https://www.jianshu.com/p/bc9bd4a1ab41
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞