zookeeper中有一個(gè)C客戶端為PHP-Zookeeper提供類庫(kù)末捣。
安裝PHP-Zookeeper類庫(kù)
zookeeper安裝目錄: /appServer/zookeeper-3.4.9
# /appServer/zookeeper-3.4.9/src/c
# ./configure
# make && make instal
安裝php的zookeeper擴(kuò)展
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
程序測(cè)試:
$ cat test.php
<?php
$zc = new Zookeeper();
$zc->connect('localhost:2181');
//嘗試查詢節(jié)點(diǎn)數(shù)據(jù)
var_dump($zc->get('/server_host'));
$ /appServer/php5.6/bin/php -f test.php
string(32) "這是一個(gè)測(cè)試數(shù)據(jù),哈哈!"
到此結(jié)束!