<?php
$zookeeper = new Zookeeper('locahost:2181');
$aclArray = array(
array(
'perms' => Zookeeper::PERM_ALL,
'scheme' => 'world',
'id' => 'anyone',
)
);
$path = '/path/to/newnode';
$realPath = $zookeeper->create($path, null, $aclArray);
if ($realPath)
echo $realPath;
else
echo 'ERR';
?>
在创建/path/to/newnode的时候
报错Uncaught exception 'ZookeeperNoNodeException' with message 'no node',通过在git上找到了例子
/**
* Equivalent of “mkdir -p” on ZooKeeper
*
* @param string pathThepathtothenode∗@paramstringvalue The value to assign to each new node along the path
*
* @return bool
*/
public function makePath(path,value = ”) {
parts=explode(′/′,path);
parts=arrayfilter(parts);
subpath=”;while(count(parts) > 1) {
subpath.=′/′.arrayshift(parts);
if (!this−>zookeeper−>exists(subpath)) {
this−>makeNode(subpath, $value);
}
}
}“`
原来要创建多层次的node,需要进行递归创建。