Open doubaokun opened 11 years ago
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.
I run PHP in daemon mode. Some times the node disappeared in zookeeper, and I am sure the process is running.
When I testing the EPHEMERAL node creation, the EPHEMERAL node disappear before process die.