PHP扩展 -- 安装zookeeper扩展

PHP:7.1.30
php-config的位置:/usr/bin/php-config

之前安装的zookeeper-3.4.5是解压版的,不需要编译,目录 /usr/local/zookeeper ,这个不动它,需要再安装一个编译版的。
到时候,解压版的用来提供服务,编译版的用来供PHP调用;之前尝试在解压版里面来编译,发现编译不成功,只能再整一个了。

cd /usr/local

wget http://archive.apache.org/dist/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz
tar -zxf zookeeper-3.4.5.tar.gz
mv zookeeper-3.4.5 libzookeeper
cd libzookeeper/src/c
./configure --prefix=/usr/local/libzookeeper
make & make install

报错:'aclocal-1.15' is missing on your system
解决:https://blog.csdn.net/raoxiaoya/article/details/98970596

make & make install

安装成功!

接下来安装 php-zookeeper

cd /usr/local

wget http://pecl.php.net/get/zookeeper-0.6.4.tgz

tar -zxf zookeeper-0.6.4.tgz

cd zookeeper-0.6.4

./configure --with-php-config=/usr/bin/php-config --with-libzookeeper-dir=/usr/local/libzookeeper
报错:bash: ./configure: 没有那个文件或目录

phpize

./configure --with-php-config=/usr/bin/php-config --with-libzookeeper-dir=/usr/local/libzookeeper

make & make install

中途会提示执行 make test

安装完毕!

根据输出提示,zookeeper.so文件在 /usr/local/zookeeper-0.6.4/modules/zookeeper.so,我们需要将其复制到PHP扩展目
录,先找到扩展目录

php -i | grep extension_dir

cp /usr/local/zookeeper-0.6.4/modules/zookeeper.so /usr/lib64/php/modules/zookeeper.so

vi /etc/php.ini
添加 extension=zookeeper.so

重启php-fpm

service php-fpm restart

php -m

先通过zk客户端设置值 create /test1 data1

代码测试:
zk-test.php

exists($path)) {
	$value = $zookeeper->get($path);
}

var_dump($value);// data1

php-zookeeper参考文档:https://www.php.net/manual/zh/book.zookeeper.php
php-zookeeper作者demo https://github.com/andreiz/php-zookeeper/blob/master/examples/Zookeeper_Example.php

你可能感兴趣的:(PHP,zookeeper)