GithubHelp home page GithubHelp logo

php-zookeeper's People

Contributors

andreiz avatar asm89 avatar faabiosr avatar fadimko avatar ganeshchandrasekaran avatar gutza avatar haiwenzhu avatar jeftom avatar mlboy avatar niettcat avatar quipo avatar ryanuber avatar timandes 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  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

php-zookeeper's Issues

::get() can fetch 512 bytes at most

Hi guys,

I found there is the hard-coded limitation in the ::get() function.

I have some simple code to fix it, and the idea is.

  • put the buffer to be static and big enough (say 1MB, align with the zk java community convention)
  • 1st read to get node dataLength, 2nd read to fetch them all.

Of coz it should only work in single PHP thread, and to make it work with malloc/free is not hard.

Thanks,
Jeff

zookeeper

Libzookeeper operation to increase the number of Kafka links

  `  if (!is_null($timeout) && is_numeric($timeout)) {
        $this->zookeeper = new \ZooKeeper($hostList, null, $timeout);
    } else {
        $this->zookeeper = new \ZooKeeper($hostList);
    }

`

update ......

Error while installing

Hey people!

I'm following these instructions and I'm getting this error when running ./configure after phpize:

configure: error: Can't find zookeeper headers under "/usr/share/zookeeper"

I already verified that the path exists, and I also tried to install via pecl. That gives the same error (with other versions of the extension too).

How do I resolve this?

Segmentation fault when printing a node

I get a segmentation fault when printing (using var_dump() or print_r()) a non-leaf node in zookeeper.
Reproducing script:

<?php
$path = '/brokers';

$zookeeper = new Zookeeper('localhost:2181');
var_dump($zookeeper->exists($path));

$node = $zookeeper->get($path);
var_dump($node);

output:

array(11) {
  ["czxid"]=>
  float(4294967318)
  ["mzxid"]=>
  float(4294967318)
  ["ctime"]=>
  float(1323252256252)
  ["mtime"]=>
  float(1323252256252)
  ["version"]=>
  int(0)
  ["cversion"]=>
  int(2)
  ["aversion"]=>
  int(0)
  ["ephemeralOwner"]=>
  float(0)
  ["dataLength"]=>
  int(0)
  ["numChildren"]=>
  int(2)
  ["pzxid"]=>
  float(4294967323)
}


string(-1) "Segmentation fault

if I set the $path to '/brokers/' (with the trailing slash) there's no segmentation fault.

Tested on CentOS release 5.7 (Final), x86_64. PHP 5.3.14.

Zookeeper connection timeout

2013-08-29 14:52:28,915:28847(0x1029c1000):ZOO_WARN@zookeeper_interest@1557: Exceeded deadline by 88155ms
2013-08-29 14:52:28,915:28847(0x1029c1000):ZOO_ERROR@handle_socket_error_msg@1643: Socket [192.168.1.149:2181] zk retcode=-7, errno=60(Operation timed out): connection to 192.168.1.149:2181 timed out (exceeded timeout by 84822ms)
2013-08-29 14:52:28,915:28847(0x1029c1000):ZOO_WARN@zookeeper_interest@1557: Exceeded deadline by 88155ms

getting error while compiling

I am gettign the following error when running a make test:

php-zookeeper/modules/zookeeper.so: undefined symbol: __mb_sb_limit in Unknown on line 0

this is also happening when I load php after adding the extension to the .ini

sometimes php example callback segmentation fault

}
NULL
NULL
array(2) {
[0]=>
string(3) "001"
[1]=>
string(3) "002"
}
[2] 4709 segmentation fault php EdjConfigCenter.php
NULL
array(2) {
[0]=>
string(3) "001"
[1]=>
string(3) "002"
}
PHP Warning: Unknown: error: zookeeper is closing in Unknown on line 0

Warning: Unknown: error: zookeeper is closing in Unknown on line 0
[1] 5070 segmentation fault php Zookeeper_Example.php

What exactly getChildren function does internally ?

I have 3 zookeepers running and while creating Zookeeper object I specify csv of all 3 hosts.

For eg. \ZooKeeper("host1:port1,host2:port2,host3:port2", null, $timeout);

If I kill one zookeeper node I get 'connection loss' error sometimes from getChildren.
If I kill 2 zookeeper nodes I am always getting 'connection loss' error.

Does getchildren tries to connect to all zookeeper nodes ?
Can someone explain what this fuction internally does ?

Don't bail out on null callback in exists().

Looks like the same issue I reported with getChildren()

I believe line 339:

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|f", &path, &path_len, &fci,

Should have ! added after the f:

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|f!", &path, &path_len, &fci,

Thanks!

get with a watcher could not invoke the watcher callback

class ZookeeperDemo extends Zookeeper {

    public function watcher( $i, $type, $key ) { 
        echo "Insider Watcher\n";

        // Watcher gets consumed so we need to set a new one
        $this->get( '/bar', array($this, 'watcher' ) );
    }   

}

$zoo = new ZookeeperDemo('127.0.0.1:2181');
$zoo->set('/bar', 1); 
$zoo->get( '/bar', array($zoo, 'watcher') );

while( true ) { 
    echo '.';
    sleep(2);
}

running this in php-5.5.6 will report a php warning:
PHP Warning: Unknown: could not invoke watcher callback in Unknown on line 0

Exception

When we will have a version with exceptions support?

Unable to disable sessions

When compiling with --disable-zookeeper-session the .so is a different file size, however, it still maintains the same session ID between reconnects. It's almost as if the client library is handling the session regardless. Is this expected behavior?

Basically, I am trying to reconnect if the connection is lost, but do not want to maintain session. Tried many methods and the only thing that works is destroying the object instance and creating a new one (not very elegant...)

Perhaps this could be solved by implementing the close() method? It is documented in the zookeeper-api.php but is not in the c code. Not sure what happened there?

Any idea or feedback on this issue would be greatly appreciated, thanks!

Build instructions

Some instructions for newbies on how to build from source in the README.md would be appreciated...

On Ubuntu 12.10, I believe they look like this:

sudo apt-get install php-pear
sudo apt-get install libzookeeper-mt-dev
pear build

for now, this is failing for me:

/php-zookeeper/php_zookeeper.c:1114:1: error: 'ZOO_NOTCONNECTED_STATE' undeclared (first use in this function)
php-zookeeper/php_zookeeper.c:1114:1: note: each undeclared identifier is reported only once for each function it appears in

What versions are expected? I'm using libzookeeper-mt-dev (3.3.5+dfsg1-1ubuntu1)

get with a watcher could not invoke the watcher callback

class Zookeeper_Module {

    private $zookeeper;

    public function __construct(){
        $this->ci = & get_instance();
        $zookeeper_server = $this->ci->config->item('zookeeper_server');

        $this->zookeeper = new Zookeeper($zookeeper_server);
    }

    public function set($path, $value){
        $this->zookeeper->set($path, $value);
    }

    public function get($path, $watch_cb = null){
        return $this->zookeeper->get($path, $watch_cb);
    }

    public function get_watch_cb($event_type = '', $stat = '', $path = ''){
        error_log('hello from get_watcher_cb');
        $value = $this->get($path, array($this, 'get_watch_cb'));
        // update redis cache
        $this->ci->cache->redis->save('some cache key', $value);
    }
}

class MyTest{
    public function get(){
        $zookeeper = new Zookeeper_Module ();

        $value = $zookeeper->get( '/foo/bar', array (
            $zookeeper,
            'get_watch_cb'
        ) );
    }

    public function set(){
        $zookeeper = new Zookeeper_Module ();
        $zookeeper->set( '/foo/bar', 'some value');
    }
}

Running this in php-5.6.14 thread safety disabled, get($path , $watch_cb) and set($path, $value) work fine, but the get_watch_cb function never works.

This is very similar with #34, but my php is thread safety disabled, so it doesn't have much help.

makePath

public function makePath($path, $value = '') {
		$parts = explode('/', $path);
		$parts = array_filter($parts);
		$subpath = '';
		while (count($parts) > 1) {
			$subpath .= '/' . array_shift($parts);
			if (!$this->zookeeper->exists($subpath)) {
				$this->makeNode($subpath, $value);
			}
		}
	}

while (count($parts) > 1) { // > 1 or >= 1?????

Tag new release version?

Hi, there's not been a new tagged release for over a year even though there are quite a few changes. Could we get a version 0.2.2 tagged and pushed to PECL if the current version is stable enough?

Diff: v0.2.1...master

One specific bug which prevents this module building under 5.4 appears to be fixed by the current code: https://bugs.php.net/bug.php?id=64336

node with null data cause php segfault at Zookeeper::get($path)

In php_zookeeper.c:334

static PHP_METHOD(Zookeeper, get)
{
...
    //!! zoo_wget set length = -1 indicate that buffer is null, 
    status = zoo_wget(i_obj->zk, path, (fci.size != 0) ? php_zk_watcher_marshal : NULL,
                      cb_data, buffer, &length, &stat);
     //!! length = -1
     buffer[length] = 0;
...

    //!! length=-1 for RETURN_STRINGL, suppose
    //!! if (length == -1) RETURN_NULL();
    RETURN_STRINGL(buffer, length, 0);
}

--with-libdir not honoured

in config.m4

 PHP_ADD_LIBRARY_WITH_PATH(zookeeper_mt, $PHP_LIBZOOKEEPER_DIR/lib, ZOOKEEPER_SHARED_LIBADD)

Should be

 PHP_ADD_LIBRARY_WITH_PATH(zookeeper_mt, $PHP_LIBZOOKEEPER_DIR/$PHP_LIBDIR, ZOOKEEPER_SHARED_LIBADD)

getChildren Fails

getChildren() will fail if you pass null for the callback. Normally you would just omit the parameter but in the case you are extending the the Zookeeper class, your function ends up passing the variable as null.

$zk->getChildren('/test', null); //returns null
$zk->getChildren('/test'); //returns array of znodes

This is what I was doing when I discovered the issue. If you omit $watcher_cb then its assigned value null, but since its passed in the parent call it silently breaks and returns NULL.

class zk extends Zookeeper {
public function getChildren( $path, $watcher_cb = null) {
return parent::getChildren( $path, $watcher_cb );
}
}

when I use while foreach the get and getchildren function, It is error...

when I use while foreach the get and getchildren function, It is error...

PHP Fatal error: Non-static method Zookeeper::get() cannot be called statically in /root/source/EdjZkConfig.php on line 68

Fatal error: Non-static method Zookeeper::get() cannot be called statically in /root/source/EdjZkConfig.php on line 68
PHP Warning: Unknown: error: zookeeper is closing in Unknown on line 0

Warning: Unknown: error: zookeeper is closing in Unknown on line 0
段错误 (core dumped)

Installing with php 7

When installing using sudo pecl install zookeeper-0.3.1 I get the following trace for compilation:

Starting to download zookeeper-0.3.1.tgz (24,087 bytes)
........done: 24,087 bytes
11 source files, building
running: phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
building in /private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1
running: /private/tmp/pear/temp/zookeeper/configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-apple-darwin15.4.0
checking host system type... x86_64-apple-darwin15.4.0
checking target system type... x86_64-apple-darwin15.4.0
checking for PHP prefix... /usr/local/php5
checking for PHP includes... -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226
checking for PHP installed headers prefix... /usr/local/php5/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable zookeeper support... yes, shared
checking whether to enable zookeeper session handler support... yes
checking for libzookeeper... yes, shared
checking for libzookeeper location... /usr/local
checking whether zookeeper session handler is enabled... enabled
checking for session includes... /usr/local/php5/include/php
checking for ld used by cc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 196608
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fno-common
checking if cc PIC flag -fno-common works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin15.4.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/libtool --mode=compile cc -I/usr/local/php5/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/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/php5/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/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
/bin/sh /private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/libtool --mode=compile cc -I/usr/local/php5/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib -I/usr/local/include/zookeeper  -DHAVE_CONFIG_H  -g -O2   -c /private/tmp/pear/temp/zookeeper/zoo_lock.c -o zoo_lock.lo
 cc -I/usr/local/php5/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib -I/usr/local/include/zookeeper -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/zookeeper/zoo_lock.c  -fno-common -DPIC -o .libs/zoo_lock.o
/private/tmp/pear/temp/zookeeper/zoo_lock.c:260:43: warning: format specifies type 'unsigned long' but the argument has type 'int64_t' (aka 'long long') [-Wformat]
        snprintf(prefix, 30, "x-%016lx-", session);
                                ~~~~~~    ^~~~~~~
                                %016llx
/usr/include/secure/_stdio.h:57:62: note: expanded from macro 'snprintf'
  __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
                                                             ^~~~~~~~~~~
1 warning generated.
/bin/sh /private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/libtool --mode=compile cc -I/usr/local/php5/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib -I/usr/local/include/zookeeper  -DHAVE_CONFIG_H  -g -O2   -c /private/tmp/pear/temp/zookeeper/php_zookeeper_session.c -o php_zookeeper_session.lo
 cc -I/usr/local/php5/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib -I/usr/local/include/zookeeper -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/zookeeper/php_zookeeper_session.c  -fno-common -DPIC -o .libs/php_zookeeper_session.o
/bin/sh /private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/libtool --mode=compile cc -I/usr/local/php5/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib -I/usr/local/include/zookeeper  -DHAVE_CONFIG_H  -g -O2   -c /private/tmp/pear/temp/zookeeper/php_zookeeper_exceptions.c -o php_zookeeper_exceptions.lo
 cc -I/usr/local/php5/include/php -I. -I/private/tmp/pear/temp/zookeeper -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib -I/usr/local/include/zookeeper -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/zookeeper/php_zookeeper_exceptions.c  -fno-common -DPIC -o .libs/php_zookeeper_exceptions.o
/bin/sh /private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/libtool --mode=link cc -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/include -I/private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/main -I/private/tmp/pear/temp/zookeeper -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib -I/usr/local/include/zookeeper  -DHAVE_CONFIG_H  -g -O2   -o zookeeper.la -export-dynamic -avoid-version -prefer-pic -module -rpath /private/tmp/pear/temp/pear-build-rootJVDCyH/zookeeper-0.3.1/modules  php_zookeeper.lo zoo_lock.lo php_zookeeper_session.lo php_zookeeper_exceptions.lo -Wl,-rpath,/usr/local/lib -L/usr/local/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/lib -lzookeeper_mt  -Wl,-rpath -Wl,/usr/local/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
ERROR: `make' failed

Do you know about this error?

Thanks

Segment fault when calling get() in a loop

//.....
$this->zk = new Zookeeper(hostname);
$service_list = $this->zk ->getChildren("/XXX");
for ($i=0; $i < count($service_list); $i++) {
if($this->zk ->exists("/XXX/".$service_list[$i])){
$app_status_json = $this->zk->get("/XXX/".$service_list[$i]);
//.....
}
}

The get() will fail when the loop count grows.

Closing Connection Properly?

I'm seeing an exception on the Zookeeper side about the client closing the connection:

[2013-08-30 14:54:44,560] INFO Accepted socket connection from /10.0.0.108:60358 (org.apache.zookeeper.server.NIOServerCnxn)
[2013-08-30 14:54:44,561] INFO Client attempting to establish new session at /10.0.0.108:60358 (org.apache.zookeeper.server.NIOServerCnxn)
[2013-08-30 14:54:44,568] INFO Established session 0x140cfa4ae54000c with negotiated timeout 10000 for client /10.0.0.108:60358 (org.apache.zookeeper.server.NIOServerCnxn)
[2013-08-30 14:54:44,705] INFO Processed session termination for sessionid: 0x140cfa4ae54000c (org.apache.zookeeper.server.PrepRequestProcessor)
[2013-08-30 14:54:44,705] WARN EndOfStreamException: Unable to read additional data from client sessionid 0x140cfa4ae54000c, likely client has closed socket (org.apache.zookeeper.server.NIOServerCnxn)
[2013-08-30 14:54:44,706] INFO Closed socket connection for client /10.0.0.108:60358 which had sessionid 0x140cfa4ae54000c (org.apache.zookeeper.server.NIOServerCnxn)
[2013-08-30 14:54:44,714] ERROR Unexpected Exception:  (org.apache.zookeeper.server.NIOServerCnxn)
java.nio.channels.CancelledKeyException
        at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:73)
        at sun.nio.ch.SelectionKeyImpl.interestOps(SelectionKeyImpl.java:77)
        at org.apache.zookeeper.server.NIOServerCnxn.sendBuffer(NIOServerCnxn.java:418)
        at org.apache.zookeeper.server.NIOServerCnxn.sendResponse(NIOServerCnxn.java:1509)
        at org.apache.zookeeper.server.FinalRequestProcessor.processRequest(FinalRequestProcessor.java:367)
        at org.apache.zookeeper.server.SyncRequestProcessor.flush(SyncRequestProcessor.java:161)
        at org.apache.zookeeper.server.SyncRequestProcessor.run(SyncRequestProcessor.java:98)

Is there a more graceful way we can close explictly close the connection so not cause an exception on the Zookeeper side?

Thanks,
Jake

Segment fault

I run PHP in daemon mode, some times PHP die with segment fault. That occurs when the process receive watch events or subscribe the watch events.

watch don't work

https://github.com/andreiz/php-zookeeper/wiki..
don't work. when i set /YuChao/test/page/page_index 11 have no effect。

Any problems?

Centos:
#php -v
PHP 5.6.33 (cli) (built: Jan 14 2018 08:26:10)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

#php -i| grep zookeeper
Registered save handlers => files user zookeeper
zookeeper
zookeeper support => enabled
libzookeeper version => 3.4.11
zookeeper.recv_timeout => 10000 => 10000
zookeeper.sess_lock_wait => 150000 => 150000
zookeeper.session_lock => 1 => 1

#php -i| grep Thread
Thread Safety => disabled

Zookeeper servers will create a lot of sessions when using php_zookeeper under FCGI mode.

When using php_zookeeper under FCGI mode, it causes servers frequently create and close zookeeper sessions, and generate a lot of log lines.

I'v noticed that the 4th parameter of function zookeeper_init is always set to 0.
Is there any better idea to reuse zookeeper session that former script created?

4/28/15 10:34:10 AM CST session 0x34cf9c251bcdfcf cxid 0x5536fed1 zxid 0x2002ae20a closeSession null
4/28/15 10:34:10 AM CST session 0x34cf9c251bcdfd9 cxid 0x553700ba zxid 0x2002ae20b closeSession null
4/28/15 10:34:10 AM CST session 0x54cf9c2a711e182 cxid 0x5538d4fc zxid 0x2002ae20c closeSession null
4/28/15 10:34:10 AM CST session 0x24cf9c2391de40e cxid 0x0 zxid 0x2002ae20d createSession 10000

4/28/15 10:34:10 AM CST session 0x14cfddc1ea871ab cxid 0x5538c42c zxid 0x2002ae20e closeSession null
4/28/15 10:34:10 AM CST session 0x44cf9c2bd0fe14e cxid 0x5536ffe9 zxid 0x2002ae20f closeSession null
4/28/15 10:34:10 AM CST session 0x24cf9c2391de40f cxid 0x0 zxid 0x2002ae210 createSession 10000

4/28/15 10:34:10 AM CST session 0x24cf9c2391de410 cxid 0x0 zxid 0x2002ae211 createSession 10000

4/28/15 10:34:10 AM CST session 0x54cf9c2a711e192 cxid 0x0 zxid 0x2002ae212 createSession 10000

4/28/15 10:34:10 AM CST session 0x14cfddc1ea871ac cxid 0x0 zxid 0x2002ae213 createSession 10000

4/28/15 10:34:10 AM CST session 0x24cf9c2391de411 cxid 0x0 zxid 0x2002ae214 createSession 10000

4/28/15 10:34:10 AM CST session 0x44cf9c2bd0fe150 cxid 0x0 zxid 0x2002ae215 createSession 10000

4/28/15 10:34:10 AM CST session 0x34cf9c251bcdfc8 cxid 0x5536fc68 zxid 0x2002ae216 closeSession null
4/28/15 10:34:10 AM CST session 0x24cf9c2391de412 cxid 0x0 zxid 0x2002ae217 createSession 10000

4/28/15 10:34:10 AM CST session 0x14cfddc1ea871a9 cxid 0x5536fc65 zxid 0x2002ae218 closeSession null
4/28/15 10:34:10 AM CST session 0x14cfddc1ea871ac cxid 0x55370351 zxid 0x2002ae219 closeSession null
4/28/15 10:34:10 AM CST session 0x44cf9c2bd0fe150 cxid 0x5536ff31 zxid 0x2002ae21a closeSession null
4/28/15 10:34:10 AM CST session 0x24cf9c2391de40e cxid 0x55370032 zxid 0x2002ae21b closeSession null
4/28/15 10:34:10 AM CST session 0x34cf9c251bcdfda cxid 0x0 zxid 0x2002ae21c createSession 10000

4/28/15 10:34:10 AM CST session 0x24cf9c2391de412 cxid 0x55370034 zxid 0x2002ae21d closeSession null
4/28/15 10:34:10 AM CST session 0x14cfddc1ea871a5 cxid 0x5538c3c4 zxid 0x2002ae21e closeSession null
4/28/15 10:34:10 AM CST session 0x44cf9c2bd0fe14c cxid 0x5538bf30 zxid 0x2002ae21f closeSession null
4/28/15 10:34:10 AM CST session 0x14cfddc1ea871ad cxid 0x0 zxid 0x2002ae220 createSession 10000

watch error:PHP Fatal error: Corrupted fcall_info provided to zend_call_function()

<?php
/**
 * PHP Zookeeper
 *
 * PHP Version 5.3
 *
 * The PHP License, version 3.01
 *
 * @category  Libraries
 * @package   PHP-Zookeeper
 * @author    Lorenzo Alberton <[email protected]>
 * @copyright 2012 PHP Group
 * @license   http://www.php.net/license The PHP License, version 3.01
 * @link      https://github.com/andreiz/php-zookeeper
 */

/**
 * Example interaction with the PHP Zookeeper extension
 *
 * @category  Libraries
 * @package   PHP-Zookeeper
 * @author    Lorenzo Alberton <[email protected]>
 * @copyright 2012 PHP Group
 * @license   http://www.php.net/license The PHP License, version 3.01
 * @link      https://github.com/andreiz/php-zookeeper
 */
class Zookeeper_Example
{
	/**
	 * @var Zookeeper
	 */
	private $zookeeper;

    /**
      * @var Callback container
      */
    private $callback = array();

	/**
	 * Constructor
	 *
	 * @param string $address CSV list of host:port values (e.g. "host1:2181,host2:2181")
	 */
	public function __construct($address) {
		$this->zookeeper = new Zookeeper($address);
	}

	/**
	 * Set a node to a value. If the node doesn't exist yet, it is created.
	 * Existing values of the node are overwritten
	 *
	 * @param string $path  The path to the node
	 * @param mixed  $value The new value for the node
	 *
	 * @return mixed previous value if set, or null
	 */
	public function set($path, $value) {
		if (!$this->zookeeper->exists($path)) {
			$this->makePath($path);
			$this->makeNode($path, $value);
		} else {
			$this->zookeeper->set($path, $value);
		}
	}

	/**
	 * Equivalent of "mkdir -p" on ZooKeeper
	 *
	 * @param string $path  The path to the node
	 * @param string $value The value to assign to each new node along the path
	 *
	 * @return bool
	 */
	public function makePath($path, $value = '') {
		$parts = explode('/', $path);
		$parts = array_filter($parts);
		$subpath = '';
		while (count($parts) > 1) {
			$subpath .= '/' . array_shift($parts);
			if (!$this->zookeeper->exists($subpath)) {
				$this->makeNode($subpath, $value);
			}
		}
	}

	/**
	 * Create a node on ZooKeeper at the given path
	 *
	 * @param string $path   The path to the node
	 * @param string $value  The value to assign to the new node
	 * @param array  $params Optional parameters for the Zookeeper node.
	 *                       By default, a public node is created
	 *
	 * @return string the path to the newly created node or null on failure
	 */
	public function makeNode($path, $value, array $params = array()) {
		if (empty($params)) {
			$params = array(
				array(
					'perms'  => Zookeeper::PERM_ALL,
					'scheme' => 'world',
					'id'     => 'anyone',
				)
			);
		}
		return $this->zookeeper->create($path, $value, $params);
	}

	/**
	 * Get the value for the node
	 *
	 * @param string $path the path to the node
	 *
	 * @return string|null
	 */
	public function get($path) {
		if (!$this->zookeeper->exists($path)) {
			return null;
		}
		return $this->zookeeper->get($path);
	}

	/**
	 * List the children of the given path, i.e. the name of the directories
	 * within the current node, if any
	 *
	 * @param string $path the path to the node
	 *
	 * @return array the subpaths within the given node
	 */
	public function getChildren($path) {
		if (strlen($path) > 1 && preg_match('@/$@', $path)) {
			// remove trailing /
			$path = substr($path, 0, -1);
		}
		return $this->zookeeper->getChildren($path);
	}

	/**
	 * Delete the node if it does not have any children
	 *
	 * @param string $path the path to the node
	 *
	 * @return true if node is deleted else null
	 */

	 public function deleteNode($path)
	 {
	 	if(!$this->zookeeper->exists($path))
	 	{
	 		return null;
	 	}
	 	else
	 	{
	 		return $this->zookeeper->delete($path);
	 	}
	 }

    /**
	 * Wath a given path
	 * @param string $path the path to node
	 * @param callable $callback callback function
	 * @return string|null
	 */
	public function watch($path, $callback)
	{
		if (!is_callable($callback)) {
			return null;
		}

		if ($this->zookeeper->exists($path)) {
			if (!isset($this->callback[$path])) {
				$this->callback[$path] = array();
			}
			if (!in_array($callback, $this->callback[$path])) {
				$this->callback[$path][] = $callback;
				return $this->zookeeper->get($path, array($this, 'watchCallback'));
			}
		}
	}

	/**
	 * Wath event callback warper
	 * @param int $event_type
	 * @param int $stat
	 * @param string $path
	 * @return the return of the callback or null
	 */
	public function watchCallback($event_type, $stat, $path)
	{
		if (!isset($this->callback[$path])) {
			return null;
		}

		foreach ($this->callback[$path] as $callback) {
			$this->zookeeper->get($path, array($this, 'watchCallback'),$stat);
			return call_user_func($callback);
		}
	}

	/**
	 * Delete watch callback on a node, delete all callback when $callback is null
	 * @param string $path
	 * @param callable $callback
	 * @return boolean|NULL
	 */
	public function cancelWatch($path, $callback = null)
	{
		if (isset($this->callback[$path])) {
			if (empty($callback)) {
				unset($this->callback[$path]);
				$this->zookeeper->get($path); //reset the callback
				return true;
			} else {
				$key = array_search($callback, $this->callback[$path]);
				if ($key !== false) {
					unset($this->callback[$path][$key]);
					return true;
				} else {
					return null;
				}
			}
		} else {
			return null;
		}
	}
}


$zk = new Zookeeper_Example("localhost:2181");

function callback() {
    echo "in watch callback\n";
}

$zk->set("/test123","abc");
$ret = $zk->watch("/test123", "callback");
$zk->set("/bar", 1);
$ret = $zk->watch("/bar", "callback");

while (true) {
    sleep(1);	
    zookeeper_dispatch();
}

I set path value many times it's crash and error msg:PHP Fatal error: Corrupted fcall_info provided to zend_call_function() in

Env:php5.6 and php7.0

The steps as follows:
1:set /test123 1;
2:set /bar 1;
3:set /bar 1;
4:set /test123 1; this time it's crash

wrong msg in PHP5.6

if LINE 26 is "class Zookeeper_Example extends Zookeeper",
it will case a memory wrong like "[1] 55536 segmentation fault php zk_example.php".

if LINE 26 is "class Zookeeper_Example"
it will case a PHP wrong like "PHP Fatal error: Using $this when not in object context in /opt/src/zk_example.php on line 55" .

so LINE 26 should be "class Zookeeper_Example extends Zookeeper", the problem may be in the extensiong zookeeper of PHP, in that C files??

i pull a request change the LINE 26, and i will see the extension file of zookeeper files, if i fix , i will update here, THX~

It seems memory leak when new zookeeper

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /root/CrondNG-FrontEnd/app/Services/Zookeeper.php on line 45

line 45 :

$this->zookeeper = new Zookeeper($address);

watcher not work

`$zk->get('/test', 'mywatch');

function mywatch($eventType, $eventState, $eventKey)
{
echo 'listen node';
print_r(func_get_args());
}
`

i add node /test/a, or remove it,
mywatch function not work,

PHP7.0.24 NTS

Method 'set' can only handle string-typed value

After i tried this:

<?php
$zk = new Zookeeper("localhost:2181");
$zk->set('/test', array(1));

i got a PHP warning:

PHP Warning:  Zookeeper::set() expects parameter 2 to be string, array given in /home/xxx/zk.php on line 4
PHP Stack trace:
PHP   1. {main}() /home/xxx/zk.php:0
PHP   2. Zookeeper->set() /home/xxx/zk.php:4

Is there any plan to support various types just like Memcached::set?

Maybe we can disable some warnings.

When something was going wrong, it returns false.

We could get error code & message from getResultCode() & getResultMessage() just like php_memcached.

<?php

$zk = new Zookeeper('localhost:2181');
$r = $zk->set('/test', 123);
if (!$r) {
    echo $zk->getResultMessage() . "(#" . $zk->getResultCode() . ")";
}
echo "Done";

Does not build with php 7.1

Does not build with 7.1

First error:

/root/php-zookeeper-master/php_zookeeper.c:38:40: fatal error: ext/standard/php_smart_str.h: No such file or directory
#include <ext/standard/php_smart_str.h>
                                    ^
compilation terminated.
make: *** [php_zookeeper.lo] Error 1

Easy to fix, because php_smart_str -> php_smart_string with 7.1

Another error:

/root/php-zookeeper-master/php_zookeeper.c: In function 'zm_startup_zookeeper':
/root/php-zookeeper-master/php_zookeeper.c:1217:30: warning: assignment from incompatible pointer type [enabled by default]
zookeeper_ce->create_object = php_zk_new;
                          ^
make: *** [php_zookeeper.lo] Error 1

Reconnect failure with watches

Minimal script to reproduce is below.
Steps to reproduce:

  1. Start ZK Server, Start the client below
  2. Stop Server, wait a moment, Start Server.
  3. Upon reconnecting it will fail. You can prevent it from failing by not setting a watch during your first connection.
Zookeeper::setDebugLevel(Zookeeper::LOG_LEVEL_DEBUG);

class zookeeper_bug1 extends Zookeeper { 

    function connect_cb($type, $event, $string) {
        echo "Connect Callback\n";      
        if ($event == Zookeeper::CONNECTED_STATE ) {
             //With watch, fails upon reconnect
             $this->getChildren('/zookeeper', array($this, 'watcher_cb'));

             //No watch works fine
                //$this->getChildren('/zookeeper'); 
        }
    }

    function watcher_cb($type, $event, $string){
         echo "Watcher Callback: type=$type event=$event string=$string\n";
    }

}

$zk = new zookeeper_bug1();
$zk->connect('localhost:2181', array($zk, 'connect_cb'));

while(true){
    usleep(100000);
}

The error it outputs:

    2011-04-22 04:31:33,889:3426(0x40a26940):ZOO_INFO@check_events@1585: initiated connection to server [127.0.0.1:2181]
    2011-04-22 04:31:33,889:3426(0x40a26940):ZOO_INFO@check_events@1632: session establishment complete on server [127.0.0.1:2181], sessionId=0x12f7cf90f130000, negotiated timeout=10000
    2011-04-22 04:31:33,889:3426(0x40a26940):ZOO_DEBUG@send_set_watches@1312: Sending set watches request to 127.0.0.1:2181
    2011-04-22 04:31:33,889:3426(0x40a26940):ZOO_DEBUG@check_events@1638: Calling a watcher for a ZOO_SESSION_EVENT and the state=ZOO_CONNECTED_STATE
    2011-04-22 04:31:33,895:3426(0x42498940):ZOO_DEBUG@process_completions@1765: Calling a watcher for node [], type = -1 event=ZOO_SESSION_EVENT
    PHP Fatal error:  Corrupted fcall_info provided to zend_call_function() in zookeeper.php on line 28

    Fatal error: Corrupted fcall_info provided to zend_call_function() in zookeeper.php on line 28
    2011-04-22 04:31:33,896:3426(0x40a26940):ZOO_DEBUG@do_io@317: IO thread terminated

start-stop-daemon to start redis_failover how to save log

I try start it daemon by start-stop-daemon,because we want to see the log to know which redis is down and which tobe master!
It's ok!
But no output!
I try to add "> /var/log/redis_failover.log" into start-stop-daemon shell,but is bad!

So i think if you can add -l|--log option into redis_node_manager next version,it will so cool!

Thank you!

My start-stop-daemon shell(debian):

dev@template:/var/log$ cat /etc/init.d/redis_failover

!/bin/bash

ulimit -s 256

DAEMON=/usr/local/bin/redis_node_manager
DAEMON_OPTS="-C /etc/redis/redis_failover.yml"

PIDFILE=/var/run/goagent.pid

case "$1" in
start)
echo "Starting server"
/sbin/start-stop-daemon --start --pidfile $PIDFILE
--user root --group root
--background --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
;;
stop)
echo "Stopping server"
/sbin/start-stop-daemon --stop --pidfile $PIDFILE --verbose
;;
restart)
echo "Restarting server"
$0 stop && $0 start
;;
*)
echo "Usage: /etc/init.d/redis_failover {start|stop|restart}"
exit 1
;;
esac

exit 0

how to install with php7?

when i do the command 'make', it tells me this:

  the file or dir is not exists : ext/standard/php_smart_str.h

what's wrong with this? or It doesn't support php7 ?

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.