GithubHelp home page GithubHelp logo

php-zookeeper / php-zookeeper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andreiz/php-zookeeper

146.0 146.0 50.0 380 KB

A PHP extension for interfacing with Apache ZooKeeper

License: Other

Shell 4.08% M4 2.82% C 55.48% PHP 33.68% Dockerfile 3.23% Makefile 0.26% HTML 0.46%
pecl php zookeeper

php-zookeeper's Introduction

PHP ZooKeeper Extension

Build Status Coveralls

This extension uses libzookeeper library to provide API for communicating with ZooKeeper service.

ZooKeeper is an Apache project that enables centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.

Requirements

Install

1.Compile ZooKeeper C Binding

$ ./configure --prefix=/path/to/zookeeper-c-binding
$ make
$ sudo make install

As of ZooKeeper 3.5.0, after unpacking source tarball, the following command should be executed before above-metioned steps:

$ autoreconf -if

As of ZooKeeper 3.5.9, the following command should be executed before autoreconf -if:

$ ant compile_jute

As of ZooKeeper 3.6.0, ant will fail because of missing build.xml. That file and two other files can be found in source tarball of 3.5.9:

$ cd apache-zookeeper-3.5.9
$ cp build.xml ivy* ../apache-zookeeper-3.6.2

2.Compile PHP ZooKeeper Extension

$ phpize
$ ./configure --with-libzookeeper-dir=/path/to/zookeeper-c-binding
$ make
$ sudo make install

Examples

<?php
$zc = new Zookeeper();
$zc->connect('localhost:2181');
var_dump($zc->get('/zookeeper'));
?>

Working with other extensions

1.Swoole

Swoole\Async::set([
    'enable_signalfd' => false, // See: https://github.com/swoole/swoole-src/issues/302
]);

$zk = new Zookeeper('localhost:2181');

Swoole\Process::signal(SIGTERM, function() {
        echo "TERM" . PHP_EOL;
        Swoole\Event::exit();
    });
Swoole\Event::wait();

For Developers

Branches

  • master: Main branch.
  • 0.5.x: The last branch which still supports PHP 5.x.

Resources

php-zookeeper's People

Contributors

andreiz avatar asm89 avatar camporter avatar erikn69 avatar faabiosr avatar fadimko avatar falvarez avatar ganeshchandrasekaran avatar git-hulk avatar gutza avatar haiwenzhu avatar huang-lin avatar jbboehr avatar jeftom avatar johnpbloch avatar mlboy avatar niettcat avatar petk avatar qkdreyer avatar quipo avatar remicollet avatar ryanuber avatar sunpoet avatar timandes avatar xjewer avatar yjqg6666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-zookeeper's Issues

watcher not work

class ZookeeperDemo extends Zookeeper { public function watcher($i, $type, $key) { echo 'watcher working'; // Watcher gets consumed so we need to set a new one $this->get('/test', array($this, 'watcher')); } } $zoo = new ZookeeperDemo(); $zoo->connect('127.0.0.1:2181'); $zoo->get('/test', [$zoo,'watcher']); while (true) { echo '.'; sleep(2); }

i set /test other value in client, nothing echo.
php:PHP 7.0.20-2 (cli) (built: Jun 14 2017 05:30:04) ( NTS )

How to install from pecl?

pecl install zookeeper-1.2.1

checking for libzookeeper location... configure: error: zookeeper support requires libzookeeper. Use --with-libzookeeper-dir=

to specify the prefix where libzookeeper headers and library are located

Is there a guide how to install from pecl?

undefined symbol: zend_string_init_interned

On CentOS 7 I installed php 7.2 using remi repo:

yum install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt php-devel php-pdo

Downloaded zookeeper-3.4.10.tar.gz and did a configure make install in src/c
then with php-zookeeper:

./configure --with-libzookeeper-dir=/usr/local/lib --with-libzookeeper-dir=/root/zookeeper-3.4.10/src/c/
make 
make install

I have the module configured under /etc/php.d but when I run:

php --modules

I get:

PHP Warning:  PHP Startup: Unable to load dynamic library 'zookeeper.so' (tried: /usr/lib64/php/modules/zookeeper.so (/usr/lib64/php/modules/zookeeper.so: undefined symbol: zend_string_init_interned)

I have the php-devel package installed and have the following in my ld.so.sonf.d:

/usr/local/lib
/usr/include/php/Zend

Any ideas?

support connect zookeeper cluster ?

example,have three zookeeper server, It's a zookeeper cluster, below code doesn't work:
`
$connectStr = 'host1:2181,host2:2181,host3:2181';

$zc = new \Zookeeper($connectStr);

var_export($zc->get('xxx/xx'));
`

Segmentation fault when connect with watch_cb

$client = new Zookeeper(); $client->connect('192.168.40.65:32181', function($type, $stat, $path) { // });

`
2019-11-27 12:01:28,361:15938(0x7f4d341209c0):ZOO_INFO@log_env@1098: Client environment:zookeeper.version=zookeeper C client 3.5.6
2019-11-27 12:01:28,361:15938(0x7f4d341209c0):ZOO_INFO@log_env@1102: Client environment:host.name=liwenqiang-local-dev
2019-11-27 12:01:28,361:15938(0x7f4d341209c0):ZOO_INFO@log_env@1109: Client environment:os.name=Linux
2019-11-27 12:01:28,361:15938(0x7f4d341209c0):ZOO_INFO@log_env@1110: Client environment:os.arch=3.10.0-1062.4.3.el7.x86_64
2019-11-27 12:01:28,361:15938(0x7f4d341209c0):ZOO_INFO@log_env@1111: Client environment:os.version=#1 SMP Wed Nov 13 23:58:53 UTC 2019
2019-11-27 12:01:28,363:15938(0x7f4d341209c0):ZOO_INFO@log_env@1119: Client environment:user.name=root
2019-11-27 12:01:28,363:15938(0x7f4d341209c0):ZOO_INFO@log_env@1127: Client environment:user.home=/root
2019-11-27 12:01:28,363:15938(0x7f4d341209c0):ZOO_INFO@log_env@1139: Client environment:user.dir=/workspace/WangYuanServiceCoroutineSDK/src
2019-11-27 12:01:28,363:15938(0x7f4d341209c0):ZOO_INFO@zookeeper_init_internal@1182: Initiating client connection, host=192.168.40.65:32181 sessionTimeout=10000 watcher=0x7f4d25123d10 sessionId=0 sessionPasswd= context=(nil) flags=0
2019-11-27 12:01:28,363:15938(0x7f4d341209c0):ZOO_DEBUG@start_threads@221: starting threads...
2019-11-27 12:01:28,364:15938(0x7f4d22e44700):ZOO_DEBUG@do_completion@471: started completion thread
2019-11-27 12:01:28,364:15938(0x7f4d341209c0):ZOO_DEBUG@zoo_awexists@3821: Sending request xid=0x5dddf519 for path [/php-co/phpco.service] to :0
2019-11-27 12:01:28,364:15938(0x7f4d23645700):ZOO_DEBUG@do_io@368: started IO thread
2019-11-27 12:01:28,364:15938(0x7f4d23645700):ZOO_DEBUG@get_next_server_in_reconfig@1328: [OLD] count=0 capacity=0 next=0 hasnext=0
2019-11-27 12:01:28,364:15938(0x7f4d23645700):ZOO_DEBUG@get_next_server_in_reconfig@1331: [NEW] count=1 capacity=16 next=0 hasnext=1
2019-11-27 12:01:28,364:15938(0x7f4d23645700):ZOO_DEBUG@get_next_server_in_reconfig@1340: Using next from NEW=192.168.40.65:32181
2019-11-27 12:01:28,364:15938(0x7f4d23645700):ZOO_DEBUG@zookeeper_connect@2228: [zk] connect()

2019-11-27 12:01:28,365:15938(0x7f4d23645700):ZOO_INFO@check_events@2469: initiated connection to server [192.168.40.65:32181]
2019-11-27 12:01:28,366:15938(0x7f4d23645700):ZOO_INFO@check_events@2521: session establishment complete on server [192.168.40.65:32181], sessionId=0x100189821610260, negotiated timeout=10000
2019-11-27 12:01:28,366:15938(0x7f4d23645700):ZOO_DEBUG@check_events@2527: Calling a watcher for a ZOO_SESSION_EVENT and the state=ZOO_CONNECTED_STATE
2019-11-27 12:01:28,366:15938(0x7f4d22e44700):ZOO_DEBUG@process_completions@2807: Calling a watcher for node [], type = -1 event=ZOO_SESSION_EVENT
Segmentation fault
`

====================
PHP 7.3.11 (cli) (built: Oct 29 2019 19:31:51) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies

767:zookeeper
768-
769:zookeeper support => enabled
770-version => 0.6.4
771:libzookeeper version => 3.5.6
772-
773-Directive => Local Value => Master Value
774:zookeeper.recv_timeout => 10000 => 10000
775:zookeeper.sess_lock_wait => 150000 => 150000
776:zookeeper.session_lock => 1 => 1

[warning] php_zookeeper.c in function 'php_zk_completion_marshal

/usr/local/src/php-zookeeper/php_zookeeper.c: In function 'php_zk_completion_marshal': /usr/local/src/php-zookeeper/php_zookeeper.c:1144:27: warning: initialization discards 'const' qualifier from pointer target type [enabled by default] php_cb_data_t *cb_data = context; ^ /usr/local/src/php-zookeeper/php_zookeeper.c:1157:13: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] p->cb_data = context; ^

version info:
zookeeper-3.4.10
PHP 7.0.20

compiled from sources doesnt work

Hi

zookeeper.so has been installed from sources without any errors

php -m

/usr/lib64/php/modules/zookeeper.so: undefined symbol: php_zk_config_register

any suggestions ?

php version 7.2.9

Thanks

PHP 7.2 Support

Is there a time table for PHP 7.2 support? The pecl version of the module caps support at php 7.1.99.

undefined symbol: php_zk_config_ce

[root@192 zookeeper-0.7.2]# php-config Usage: /usr/local/bin/php-config [OPTION] Options: --prefix [/root/php/bin/php74] --includes [-I/root/php/bin/php74/include/php -I/root/php/bin/php74/include/php/main -I/root/php/bin/php74/include/php/TSRM -I/root/php/bin/php74/include/php/Zend -I/root/php/bin/php74/include/php/ext -I/root/php/bin/php74/include/php/ext/date/lib] --ldflags [] --libs [-lcrypt -lresolv -lcrypt -lrt -lrt -lm -ldl -lxml2 -lsqlite3 -lxml2 -lsqlite3 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lz -lcrypt ] --extension-dir [/root/php/bin/php74/lib/php/extensions/debug-non-zts-20190902] --include-dir [/root/php/bin/php74/include/php] --man-dir [/root/php/bin/php74/php/man] --php-binary [/root/php/bin/php74/bin/php] --php-sapis [ cli fpm phpdbg cgi] --ini-path [/root/php/bin/php74/lib] --ini-dir [] --configure-options [--prefix=/root/php/bin/php74 --enable-debug --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig] --version [7.4.18] --vernum [70418]

[root@192 zookeeper-0.7.2]# nm -D /root/php/bin/php74/lib/php/extensions/debug-non-zts-20190902/zookeeper.so | grep php_zk_config_ce U php_zk_config_ce

在swoole中watch不生效

swoole_async_set(array(
    'enable_reuse_port' => true,
    'enable_signalfd' => false, // See: https://github.com/swoole/swoole-src/issues/302
));

$serv = new Swoole\Server("0.0.0.0", 9502, SWOOLE_BASE);

$serv->set(array(
    'worker_num' => 1,
));

$serv->on('Receive', function (swoole_server $serv, $fd, $from_id, $data)
{
    $serv->send($fd, "Swoole: " . $data);
});

function recursive_listen(Zookeeper $zk_php, $path_nerve) {
    $zk_php->get($path_nerve, function ($i, $type, $key) use ($zk_php) {
        $zk_php->get($key, null, $stat);
        var_dump($i, $type, $key, $stat/*, $zk_php->get($path_nerve)*/);
        recursive_listen($zk_php, $key);
    });
}

$serv->on('WorkerStart', function ($serv, $worker_id)
{
    var_dump('start');

    $path_nerve = '/millet/service_redis_redis_config';

    $zk_php = new Zookeeper('zoo1:2181,zoo2:2181,zoo3:2181');

    recursive_listen($zk_php, $path_nerve);

  // 不加入这个循环就无法监听, 加入了才有监听
    while (1) {
        sleep(1);
    }

});

$serv->start();

上述代码中, 如果删掉while块, 则set时不会进入get的watcher, 必须加上那个while卡在那, set时才能触发watch, 不知道什么原因, 还是我用得不对, 望指点

  • php 7.3.2
  • php_zookeeper 0.6.3
  • swoole 4.2.13

New Pecl Release

Thanks for continuing to maintain this extension! Would it be possible to get a new version packaged on pecl.php.net for installation from the pecl repository on PHP 8.1 installations? Thanks!

zookeeper-0.7.2 cannot build with php 7.3

I compiled the zookeeper C binding and ran the sudo pecl install zookeeper-0.7.2 --with-libzookeeper-dir=/usr/local to install php zookeeper extension. But I ran into the following error:
running: make /bin/sh /private/tmp/pear/temp/pear-build-rootQPOaV4/zookeeper-0.7.2/libtool --mode=compile cc -I/usr/local/Cellar/[email protected]/7.3.24/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootQPOaV4/zookeeper-0.7.2/include -I/private/tmp/pear/temp/pear-build-rootQPOaV4/zookeeper-0.7.2/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/Cellar/[email protected]/7.3.24/include/php -I/usr/local/Cellar/[email protected]/7.3.24/include/php/main -I/usr/local/Cellar/[email protected]/7.3.24/include/php/TSRM -I/usr/local/Cellar/[email protected]/7.3.24/include/php/Zend -I/usr/local/Cellar/[email protected]/7.3.24/include/php/ext -I/usr/local/Cellar/[email protected]/7.3.24/include/php/ext/date/lib -I/usr/local/include/zookeeper -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/zookeeper/php_zookeeper.c -o php_zookeeper.lo mkdir .libs cc -I/usr/local/Cellar/[email protected]/7.3.24/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootQPOaV4/zookeeper-0.7.2/include -I/private/tmp/pear/temp/pear-build-rootQPOaV4/zookeeper-0.7.2/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/Cellar/[email protected]/7.3.24/include/php -I/usr/local/Cellar/[email protected]/7.3.24/include/php/main -I/usr/local/Cellar/[email protected]/7.3.24/include/php/TSRM -I/usr/local/Cellar/[email protected]/7.3.24/include/php/Zend -I/usr/local/Cellar/[email protected]/7.3.24/include/php/ext -I/usr/local/Cellar/[email protected]/7.3.24/include/php/ext/date/lib -I/usr/local/include/zookeeper -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/zookeeper/php_zookeeper.c -fno-common -DPIC -o .libs/php_zookeeper.o /private/tmp/pear/temp/zookeeper/php_zookeeper.c:1540:44: error: use of undeclared identifier 'ZOO_MAJOR_VERSION' snprintf(buf, sizeof(buf), "%ld.%ld.%ld", ZOO_MAJOR_VERSION, ZOO_MINOR_VERSION, ZOO_PATCH_VERSION); ^ /private/tmp/pear/temp/zookeeper/php_zookeeper.c:1540:63: error: use of undeclared identifier 'ZOO_MINOR_VERSION' snprintf(buf, sizeof(buf), "%ld.%ld.%ld", ZOO_MAJOR_VERSION, ZOO_MINOR_VERSION, ZOO_PATCH_VERSION); ^ /private/tmp/pear/temp/zookeeper/php_zookeeper.c:1540:82: error: use of undeclared identifier 'ZOO_PATCH_VERSION' snprintf(buf, sizeof(buf), "%ld.%ld.%ld", ZOO_MAJOR_VERSION, ZOO_MINOR_VERSION, ZOO_PATCH_VERSION); ^ 3 errors generated. make: *** [php_zookeeper.lo] Error 1 ERROR: 'make' failed

PHP 7.3 support

Hello,

Would it be possible to extend support to PHP 7.3? Currently, the pecl version of the module caps support at php 7.2.99.

undefined symbol: zoo_wgetconfig

Buld time:

/dev/shm/BUILD/php-pecl-zookeeper-0.6.0/ZTS/php_zookeeper_config_class.c: In function 'zim_ZookeeperConfig_get':
/dev/shm/BUILD/php-pecl-zookeeper-0.6.0/ZTS/php_zookeeper_config_class.c:82:14: warning: implicit declaration of function 'zoo_wgetconfig'; did you mean 'zoo_wget'? [-Wimplicit-function-declaration]
     status = zoo_wgetconfig(i_obj->php_zk->zk, (fci.size != 0) ? php_zk_watcher_marshal : NULL,
              ^~~~~~~~~~~~~~
              zoo_wget
/dev/shm/BUILD/php-pecl-zookeeper-0.6.0/ZTS/php_zookeeper_config_class.c: In function 'php_zookeeper_config_reconfig_impl':
/dev/shm/BUILD/php-pecl-zookeeper-0.6.0/ZTS/php_zookeeper_config_class.c:274:14: warning: implicit declaration of function 'zoo_reconfig'; did you mean 'zoo_htonll'? [-Wimplicit-function-declaration]
     status = zoo_reconfig(i_obj->php_zk->zk, joining, leaving, members, version, buffer, &buffer_len, &stat);
              ^~~~~~~~~~~~
              zoo_htonll

Please document minimal version required, and add a check in config.m4 for these symbols

Support for installing zookeeper extension for travis build

Hello,

I am working on a project that is writing some functional tests for an application using zookeeper. I am trying to install the zookeeper extension and libzookeeper to run those tests.

I was wondering if I could get some help on passing the libzookeeper-dir during configure...

The failure message:
https://travis-ci.org/symfony/symfony/jobs/410575167

The travis.yml changes that I am trying to make this work:
https://github.com/symfony/symfony/pull/27920/files

how to get zookeeper-c-binding?

i download the source code : apache-zookeeper-3.6.1/zookeeper-client/zookeeper-client-c,then run this command

./configure --prefix=/path/to/apache-zookeeper-3.6.1/zookeeper-client/zookeeper-client-c

and

/apache-zookeeper-3.6.1/zookeeper-client/zookeeper-client-c//include/zookeeper.h:45:10: fatal error: zookeeper.jute.h: No such file or directory
   45 | #include "zookeeper.jute.h"
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:192: php_zookeeper.lo] Error 1

这个c绑定要怎么安装编译呢?

Segmentation fault after destroying Zookeeper instance

Description

I faced Segmentation fault after destroying the Zookeeper instance.
I have created a small app to reproduce this issue: https://github.com/BaDos/ZookeeperSegmentationFault

Steps to reproduce

  • Clone repo
  • Run composer install
  • Run php test.php app:test

Expected result

In ErrorHandler.php line 48:
Notice: Undefined offset: 3 in /Users/bohdan/Sites/console-test/src/TestCommand.php on line 28

Actual result

[1] 14737 segmentation fault php test.php app:test

Reproduced on

  • PHP version: 7.1.15, 7.1.26, 7.2.15
  • OS: MacOS, Linux
  • Zookeeper version: 0.6.3, 0.7.0

Sessions not working with PHP 7.1

---- EXPECTED OUTPUT
int(123)
---- ACTUAL OUTPUT
Warning: session_start(): Failed to read session data: zookeeper (path: localhost:2181) in tests/session-basic.php on line 2

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at tests/session-basic.php:2) in tests/session-basic.php on line 8

Warning: session_start(): Failed to read session data: zookeeper (path: localhost:2181) in tests/session-basic.php on line 8

Notice: Undefined index: foo in tests/session-basic.php on line 9
NULL
---- FAILED

https://pecl.php.net/package/zookeeper 0.6.1 not update to lastest version,make fail

download from https://pecl.php.net/package/zookeeper 0.6.1 。have not update to the lastest version。

so ,will bring following error:

make && make install

error:

duplicate symbol _php_zk_config_ce in:
    .libs/php_zookeeper.o
    .libs/php_zookeeper_config_class.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [zookeeper.la] Error 1

but, I change download form github master version ,it success。

so ,please update pecl to the lastest github master version。thank you。

Compile error with php-8.0.9 enable ZTS

PHP Version:8.0.9 enable-zts
GCC Version:8.2.0
Zookeeper Version:3.4.10
php-zookeeper Version:1.0.0

compile error:
/home/php8.0/zookeeper/src/php_zookeeper.c: In function 'php_zk_watcher_marshal':
/home/php8.0/zookeeper/src/php_zookeeper.c:986:57: error: expected expression before ';' token
void *prev = tsrm_set_interpreter_context(cb_data->ctx);
^
/home/php8.0/zookeeper/src/php_zookeeper.c: In function 'php_zk_completion_marshal':
/home/php8.0/zookeeper/src/php_zookeeper.c:1032:57: error: expected expression before ';' token
void *prev = tsrm_set_interpreter_context(cb_data->ctx);

Corrupted fcall_info provided to zend_call_function() in Unknown on line 0

I want to implement a lock lib but trigger error

开始获取锁
PHP Notice:  Undefined property: ZkLock::$watching in /Users/ritoyan/imoocCode/locks/test/ZkLock.php on line 137

Notice: Undefined property: ZkLock::$watching in /Users/ritoyan/imoocCode/locks/test/ZkLock.php on line 137
PHP Fatal error:  Corrupted fcall_info provided to zend_call_function() in Unknown on line 0

Fatal error: Corrupted fcall_info provided to zend_call_function() in Unknown on line 0

maybe called by the var watching in callback

the fllow is the source code

<?php
/****************************************************************
 *                                                              *
 * Copyright (c) 2018 zuoyebang.com, Inc. All Rights Reserved.  *
 *                                                              *
 ****************************************************************
 * Created by PhpStorm.
 * User: ritoyan
 * Date: 2018/10/5
 * Time: 下午12:34
 */
class ZkLock extends Zookeeper
{
    /**
     * 锁序号文件的前缀
     *
     * @var string
     */
    public $lockPrefix = "lock-";

    /**
     * 获取失败的时候,需要监控的节点
     *
     * @var string
     */
    protected $watchPath = "";

    /**
     * 是否监控标识,循环依靠这个停止
     *
     * @var bool
     */
    public $watching = false;

    /**
     * 根据nodepath,解析node的序号
     *
     * @param $nodePath
     * @return int
     */
    protected function parseSeq($nodePath)
    {
        $parts = explode("-", $nodePath);
        return intval($parts[1]);
    }

    /**
     * 获取锁
     *
     * @param $path 锁序号存放的目录
     * @param $acl
     * @return bool
     */
    public function lock($path, $acl)
    {
        $path       = rtrim($path, "/");
        $createPath =  $path . "/" . $this->lockPrefix;

        for ($i = 0; $i < 3; $i++) {
            try {
                $lockNode = $this->create($createPath, "", $acl, Zookeeper::EPHEMERAL | Zookeeper::SEQUENCE);

                if ($lockNode) {
                    break;
                }
            } catch (ZookeeperNoNodeException $e) {
                $paths      = explode("/", trim($path, "/"));
                $nodePath   = "";
                foreach ($paths as $path) {
                    $nodePath .= "/" . $path;
                    try {
                        $ret = $this->create($nodePath, "", $acl);
                        if ($ret) {
                            continue;
                        }
                    } catch (Exception $e) {
                        break;
                    }
                    break;
                }
            } catch (Exception $e) {
                break;
            }

            return false;
        }

        $mySeq          = $this->parseSeq($lockNode);
        while (true) {
            $childNodes = $this->getChildren($path);
            $lowestSeq = $mySeq;
            $preMySeq = -1;
            $preNodePath = "";
            foreach ($childNodes as $childNode) {
                $seq = $this->parseSeq($childNode);
                if ($seq < $lowestSeq) {
                    $lowestSeq = $seq;
                }

                if ($mySeq > $seq && $seq > $preMySeq) {
                    $preMySeq = $seq;
                    $preNodePath = $childNode;
                }
            }

            if ($mySeq == $lowestSeq) {
                // 获取锁成功
                return true;
            } else {
                // 需要监听比我序号小的节点
                $watchNodePath = $path . "/" . $preNodePath;
                try {
                    $this->watch($watchNodePath);
                    continue;
                } catch (ZookeeperNoNodeException $e) {
                    var_dump(123);
                    continue;
                } catch (Exception $e) {
                    return false;
                }
            }
        }
    }

    /**
     * 监控某个节点的删除事件
     *
     * @param $nodePath
     * @return bool
     */
    public function watch($nodePath)
    {
        $this->watchPath    = $nodePath;
        $this->watching     = true;
        $ret                = $this->exists($nodePath, [$this, "watcher"]);
        while (true) {
            if (!$this->watching) {
                break;
            }
            sleep(2);
        }
        return true;
    }

    /**
     * 具体的事件触发毁掉函数
     *
     * @param $eventType int 事件类型
     * @param $stat int
     * @param $path string
     */
    public function watcher($eventType, $stat, $path)
    {
        var_dump(123);
        if (self::DELETED_EVENT == $eventType) {
            $this->watching = false;
        } else {
            $this->exists($this->watchPath, [$this, "watcher"]);
        }
    }
}


$zk = new ZkLock("localhost:2181");
echo "开始获取锁\n";
$r = $zk->lock("/yrtyyy/names", [
    [
        'perms'  => Zookeeper::PERM_ALL,
        'scheme' => 'world',
        'id'     => 'anyone',
    ]
]);

if ($r) {
    echo "获取成功\n";
} else {
    echo "获取失败\n";
}

sleep(5);
var_dump("do something\n");

PHP Compatibility

Changelog for 0.6 state Drop PHP-5 support

But package.xml still have

   <php>
    <min>5.2.0</min>
    <max>7.2.99</max>
   </php>

Connection loss problem

Hello, we are using stable (6.4) pecl package of your Zookeeper client and we have a issue.
I have a just this simple code:

<?php
$zk = new \Zookeeper("sc1.clapix.com:2181,sc2.clapix.com:2181,sc3.clapix.com:2181/solr");
$zk->setDebugLevel(\Zookeeper::LOG_LEVEL_DEBUG);
$x = $zk->exists('/aliases.json');

var_dump($zk->get('/aliases.json'));

Everything works well till I stop on one of three ZK instance on our servers.

Then I get this sometime:

2019-08-29 16:27:03,228:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1310: [OLD] count=0 capacity=0 next=0 hasnext=0
2019-08-29 16:27:03,228:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1313: [NEW] count=3 capacity=16 next=0 hasnext=1
2019-08-29 16:27:03,228:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1322: Using next from NEW=193.86.66.217:2181
2019-08-29 16:27:03,228:25057(0x7f2f104b9700):ZOO_DEBUG@zookeeper_connect@2210: [zk] connect()

2019-08-29 16:27:03,228:25057(0x7f2f2ccc0880):ZOO_DEBUG@zoo_awexists@3696: Sending request xid=0x5d67e0b8 for path [/aliases.json] to 193.86.66.217:2181
2019-08-29 16:27:03,229:25057(0x7f2f104b9700):ZOO_ERROR@handle_socket_error_msg@2444: Socket [193.86.66.217:2181] zk retcode=-4, errno=111(Connection refused): server refused to accept the client
2019-08-29 16:27:03,229:25057(0x7f2f104b9700):ZOO_DEBUG@cleanup@1763: Previous connection=[193.86.66.217:2181] delay=0
PHP Fatal error:  Uncaught ZookeeperConnectionException: connection loss in /home/jjuklicek/zktest.php:5
Stack trace:
#0 /home/jjuklicek/zktest.php(5): Zookeeper->exists('/aliases.json')
#1 {main}
  thrown in /home/jjuklicek/zktest.php on line 5

Fatal error: Uncaught ZookeeperConnectionException: connection loss in /home/jjuklicek/zktest.php:5
Stack trace:
#0 /home/jjuklicek/zktest.php(5): Zookeeper->exists('/aliases.json')
#1 {main}
  thrown in /home/jjuklicek/zktest.php on line 5
2019-08-29 16:27:03,229:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1310: [OLD] count=0 capacity=0 next=0 hasnext=0
2019-08-29 16:27:03,230:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1313: [NEW] count=3 capacity=16 next=1 hasnext=1
2019-08-29 16:27:03,230:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1322: Using next from NEW=193.86.66.215:2181
2019-08-29 16:27:03,230:25057(0x7f2f104b9700):ZOO_DEBUG@zookeeper_connect@2210: [zk] connect()

2019-08-29 16:27:03,230:25057(0x7f2f104b9700):ZOO_DEBUG@do_io@458: IO thread terminated
2019-08-29 16:27:03,230:25057(0x7f2f0fcb8700):ZOO_DEBUG@do_completion@481: completion thread terminated
2019-08-29 16:27:03,230:25057(0x7f2f2ccc0880):ZOO_INFO@zookeeper_close@3271: Freeing zookeeper resources for sessionId=0

Do you have some idea what is wrong? Is that right that one of three ZK instance failure should be ok for the client?

Thank you very much!

Duplicate symbols under php7?

Using Homebrew php7 and zookeeper:

$ ./configure --with-libzookeeper-dir=/usr/local/Cellar/zookeeper/3.4.9 --with-php-config=/usr/local/Cellar/php70/7.0.11_5/bin/php-config

make finishes with:

/bin/sh /Users/jmagnuss/repos/mainevent/work/php-zookeeper/libtool --mode=link cc -DPHP_ATOM_INC -I/Users/jmagnuss/repos/mainevent/work/php-zookeeper/include -I/Users/jmagnuss/repos/mainevent/work/php-zookeeper/main -I/Users/jmagnuss/repos/mainevent/work/php-zookeeper -I/usr/local/Cellar/php70/7.0.11_5/include/php -I/usr/local/Cellar/php70/7.0.11_5/include/php/main -I/usr/local/Cellar/php70/7.0.11_5/include/php/TSRM -I/usr/local/Cellar/php70/7.0.11_5/include/php/Zend -I/usr/local/Cellar/php70/7.0.11_5/include/php/ext -I/usr/local/Cellar/php70/7.0.11_5/include/php/ext/date/lib -I/usr/local/Cellar/zookeeper/3.4.9/include/zookeeper  -DHAVE_CONFIG_H  -g -O2   -o zookeeper.la -export-dynamic -avoid-version -prefer-pic -module -rpath /Users/jmagnuss/repos/mainevent/work/php-zookeeper/modules  php_zookeeper.lo zoo_lock.lo php_zookeeper_session.lo php_zookeeper_exceptions.lo -Wl,-rpath,/usr/local/Cellar/zookeeper/3.4.9/lib -L/usr/local/Cellar/zookeeper/3.4.9/lib -lzookeeper_mt
cc ${wl}-flat_namespace ${wl}-undefined ${wl}suppress -o .libs/zookeeper.so -bundle  .libs/php_zookeeper.o .libs/zoo_lock.o .libs/php_zookeeper_session.o .libs/php_zookeeper_exceptions.o  -L/usr/local/Cellar/zookeeper/3.4.9/lib -lzookeeper_mt  -Wl,-rpath -Wl,/usr/local/Cellar/zookeeper/3.4.9/lib
duplicate symbol _zk_optimeout_exception in:
    .libs/php_zookeeper.o
    .libs/php_zookeeper_exceptions.o
duplicate symbol _zk_connection_exception in:
    .libs/php_zookeeper.o
    .libs/php_zookeeper_exceptions.o
duplicate symbol _zk_session_exception in:
    .libs/php_zookeeper.o
    .libs/php_zookeeper_exceptions.o
duplicate symbol _zk_auth_exception in:
    .libs/php_zookeeper.o
    .libs/php_zookeeper_exceptions.o
duplicate symbol _zk_marshalling_exception in:
    .libs/php_zookeeper.o
    .libs/php_zookeeper_exceptions.o
duplicate symbol _zk_base_exception in:
    .libs/php_zookeeper.o
    .libs/php_zookeeper_exceptions.o
duplicate symbol _zk_nonode_exception in:
    .libs/php_zookeeper.o
    .libs/php_zookeeper_exceptions.o
ld: 7 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [zookeeper.la] Error 1

Any suggestions? Thanks!

Please create a release with declared support for PHP8.3

Hello, and thanks for your work supporting this extension! I just built the plugin with PHP8.3 and ran the tests with no failures. Here were the results:

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :     0
Exts tested     :    16
---------------------------------------------------------------------

Number of tests :   105                80
Tests skipped   :    25 ( 23.8%) --------
Tests warned    :     0 (  0.0%) (  0.0%)
Tests failed    :     0 (  0.0%) (  0.0%)
Tests passed    :    80 ( 76.2%) (100.0%)
---------------------------------------------------------------------
Time taken      :     1 seconds
=====================================================================

It looks like all that is required is a new release on pecl to declare support for 8.3 (currently only up to 8.2.99 has declared support).

Thanks!

php 8.2 support

New php 8.2 is out, but zookeper extension doesn't support it.
Stack trace from issue

#7 1503.6 2: /tmp/pickle.tmp/zookeeper/zookeeper-1.0.0/php_zookeeper.c: In function 'php_zk_watcher_marshal':
#7 1503.6 2: /tmp/pickle.tmp/zookeeper/zookeeper-1.0.0/php_zookeeper.c:1009:21: error: incompatible types when assigning to type 'zend_atomic_bool' {aka 'struct zend_atomic_bool_s'} from type 'int'
#7 1503.6 2:  1009 |  EG(vm_interrupt) = 1;
#7 1503.6 2:       |                     ^
#7 1503.6 2: /tmp/pickle.tmp/zookeeper/zookeeper-1.0.0/php_zookeeper.c: In function 'php_zk_completion_marshal':
#7 1503.6 2: /tmp/pickle.tmp/zookeeper/zookeeper-1.0.0/php_zookeeper.c:1053:21: error: incompatible types when assigning to type 'zend_atomic_bool' {aka 'struct zend_atomic_bool_s'} from type 'int'
#7 1503.6 2:  1053 |  EG(vm_interrupt) = 1;
#7 1503.6 2:       |                     ^
#7 1503.6 2: make: *** [Makefile:210: php_zookeeper.lo] Error 1

PHP Startup: Unable to load dynamic library 'zookeeper'

Hello.

I have a problem in enabling this extension on php 7.3 and 7.4.
I'm using version 0.7.2 of extension.

Detailed error message: PHP Warning: PHP Startup: Unable to load dynamic library 'zookeeper.so' (tried: /usr/lib/php/20180731/zookeeper.so (libzookeeper_mt.so.2: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/zookeeper.so.so (/usr/lib/php/20180731/zookeeper.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.