php-zookeeper icon indicating copy to clipboard operation
php-zookeeper copied to clipboard

The connection to zookeeper always disconnected

Open doubaokun opened this issue 11 years ago • 2 comments

When I testing the EPHEMERAL node creation, the EPHEMERAL node disappear before process die.

doubaokun avatar Aug 28 '13 01:08 doubaokun

This really depends on how you are using PHP. If you have a long-running PHP process, this works just as expected. Example:

$z = new Zookeeper('127.0.0.1:2181');
$z->create('/etest', 'blah', array(array(
    'perms' => Zookeeper::PERM_ALL,
    'scheme' => 'world',
    'id' => 'anyone')), Zookeeper::EPHEMERAL);
var_dump((bool)$z->exists('/etest'));
sleep(1);
var_dump((bool)$z->exists('/etest'));
sleep(10);
var_dump((bool)$z->exists('/etest'));
$z = null;
$z = new Zookeeper('127.0.0.1:2181');
var_dump((bool)$z->exists('/etest'));

Gives the result:

bool(true)
bool(true)
bool(true)
bool(false)

As you can see, the ephemeral node exists until the connection is closed or reset. If you are making multiple calls to PHP, the zookeeper connection is likely closed after each execution, and therefore the ephemeral node disappears as it should. Many web server PHP integrations will not work correctly with this library if you need support for ephemeral nodes, because the typical nature of PHP behind a web server is single-execution.

ryanuber avatar Aug 29 '13 05:08 ryanuber

I run PHP in daemon mode. Some times the node disappeared in zookeeper, and I am sure the process is running.

doubaokun avatar Aug 29 '13 13:08 doubaokun