使用php访问zookeeper服务
程序员文章站
2022-05-30 18:58:26
...
下载zookeeper依赖库:
http://apache.fayea.com/zookeeper/zookeeper-3.4.6/
解压
tar -zxf zookeeper-3.4.6.tar.gz
cd zookeeper-3.4.6/src/c
安装
./configure --prefix=/usr/local/zookeeper/zookeeper-3.4.6/
make & make install
下载PHPzookeeper扩展库:
http://pecl.php.net/package/zookeeper
解压
tar -zxvf zookeeper-3.4.6.tar.gz
安装
/usr/local/php5.4/bin/phpize
./configure --with-php-config=/usr/local/php5.4/bin/php-config --with-libzookeeper-dir=/usr/local/zookeeper/zookeeper-3.4.6/
make & make install
编辑配置php
vim /usr/local/conf/php5.4/php.ini
/usr/local/php5.4/bin/php -m
l /usr/local/php5.4/lib/php/extensions/no-debug-non-zts-20100525
重启fpm
kill -USR2 `cat /usr/local/php5.4/var/run/php-fpm.pid`
测试访问zookeeper服务状态:
vim test_zookeeper.php
class zookeeper_instance extends Zookeeper {
function connect_cb($type, $event, $string) {
if ($event == Zookeeper::CONNECTED_STATE) {
$acl=array(
"perms"=>0x1f,
"scheme"=>"world",
"id"=>"anyone"
);
}
}
}
$zk=new zookeeper_instance();
echo "instance ok\n";
$zk->connect("127.0.0.1:2181", array($zk, 'connect_cb'),200000);
echo "connect ok\n";
$zkm=$zk->get("/hbase/master");
var_dump($zk->getState());
var_dump($zk->getClientId());
var_dump($zk->getAcl("/hbase/master"));
var_dump($zk->getRecvTimeout());
var_dump($zkm);
echo "\n\r";
运行:
php test_zookeeper.php
结果:
instance ok
connect ok
string(65) "?20165@namenode1.dd.comnamenode1.dd.com,60000,1429518731888"
int(3)
array(2) {
[0]=>
int(165782755280355365)
[1]=>
string(18) "?.L[?c6."
}
array(2) {
[0]=>
array(11) {
["czxid"]=>
float(227633267014)
["mzxid"]=>
float(227633267014)
["ctime"]=>
float(1429518733469)
["mtime"]=>
float(1429518733469)
["version"]=>
int(0)
["cversion"]=>
int(0)
["aversion"]=>
int(0)
["ephemeralOwner"]=>
float(2.3780011668065E+17)
["dataLength"]=>
int(65)
["numChildren"]=>
int(0)
["pzxid"]=>
float(227633267014)
}
[1]=>
array(1) {
[0]=>
array(3) {
["perms"]=>
int(31)
["scheme"]=>
string(5) "world"
["id"]=>
string(6) "anyone"
}
}
}
int(40000)
http://apache.fayea.com/zookeeper/zookeeper-3.4.6/
解压
tar -zxf zookeeper-3.4.6.tar.gz
cd zookeeper-3.4.6/src/c
安装
./configure --prefix=/usr/local/zookeeper/zookeeper-3.4.6/
make & make install
下载PHPzookeeper扩展库:
http://pecl.php.net/package/zookeeper
解压
tar -zxvf zookeeper-3.4.6.tar.gz
安装
/usr/local/php5.4/bin/phpize
./configure --with-php-config=/usr/local/php5.4/bin/php-config --with-libzookeeper-dir=/usr/local/zookeeper/zookeeper-3.4.6/
make & make install
编辑配置php
vim /usr/local/conf/php5.4/php.ini
/usr/local/php5.4/bin/php -m
l /usr/local/php5.4/lib/php/extensions/no-debug-non-zts-20100525
重启fpm
kill -USR2 `cat /usr/local/php5.4/var/run/php-fpm.pid`
测试访问zookeeper服务状态:
vim test_zookeeper.php
class zookeeper_instance extends Zookeeper {
function connect_cb($type, $event, $string) {
if ($event == Zookeeper::CONNECTED_STATE) {
$acl=array(
"perms"=>0x1f,
"scheme"=>"world",
"id"=>"anyone"
);
}
}
}
$zk=new zookeeper_instance();
echo "instance ok\n";
$zk->connect("127.0.0.1:2181", array($zk, 'connect_cb'),200000);
echo "connect ok\n";
$zkm=$zk->get("/hbase/master");
var_dump($zk->getState());
var_dump($zk->getClientId());
var_dump($zk->getAcl("/hbase/master"));
var_dump($zk->getRecvTimeout());
var_dump($zkm);
echo "\n\r";
运行:
php test_zookeeper.php
结果:
instance ok
connect ok
string(65) "?20165@namenode1.dd.comnamenode1.dd.com,60000,1429518731888"
int(3)
array(2) {
[0]=>
int(165782755280355365)
[1]=>
string(18) "?.L[?c6."
}
array(2) {
[0]=>
array(11) {
["czxid"]=>
float(227633267014)
["mzxid"]=>
float(227633267014)
["ctime"]=>
float(1429518733469)
["mtime"]=>
float(1429518733469)
["version"]=>
int(0)
["cversion"]=>
int(0)
["aversion"]=>
int(0)
["ephemeralOwner"]=>
float(2.3780011668065E+17)
["dataLength"]=>
int(65)
["numChildren"]=>
int(0)
["pzxid"]=>
float(227633267014)
}
[1]=>
array(1) {
[0]=>
array(3) {
["perms"]=>
int(31)
["scheme"]=>
string(5) "world"
["id"]=>
string(6) "anyone"
}
}
}
int(40000)
以上就介绍了使用php访问zookeeper服务,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
上一篇: Smarty3入门初探
推荐阅读
-
php使用socket post数据到其它web服务器的方法
-
linux服务器上使用nginx访问本地静态资源的方法
-
PHP使用SMTP邮件服务器发送邮件示例
-
Linux下SVN服务器同时支持Apache的http和svnserve独立服务器两种模式且使用相同的访问权限账号
-
PHP5.5在windows安装使用memcached服务端的方法
-
使用PHP访问RabbitMQ消息队列的方法示例
-
Ubuntu 16.04.4 LTS环境中php7.0使用mysqli失败,数据库无法访问
-
php使用cookie显示用户上次访问网站日期的方法
-
Apache2.4.x版wampserver本地php服务器如何让外网访问及启用.htaccess
-
PHP内置服务器的使用步骤