class Zookeeper (View source)

Zookeeper class.

Constants

PERM_READ

PERM_WRITE

PERM_CREATE

PERM_DELETE

PERM_ADMIN

PERM_ALL

EPHEMERAL

SEQUENCE

EXPIRED_SESSION_STATE

AUTH_FAILED_STATE

CONNECTING_STATE

ASSOCIATING_STATE

CONNECTED_STATE

NOTCONNECTED_STATE

CREATED_EVENT

DELETED_EVENT

CHANGED_EVENT

CHILD_EVENT

SESSION_EVENT

NOTWATCHING_EVENT

LOG_LEVEL_ERROR

LOG_LEVEL_WARN

LOG_LEVEL_INFO

LOG_LEVEL_DEBUG

SYSTEMERROR

RUNTIMEINCONSISTENCY

DATAINCONSISTENCY

CONNECTIONLOSS

MARSHALLINGERROR

UNIMPLEMENTED

OPERATIONTIMEOUT

BADARGUMENTS

INVALIDSTATE

NEWCONFIGNOQUORUM Since: 3.5

RECONFIGINPROGRESS Since: 3.5

OK

APIERROR

NONODE

NOAUTH

BADVERSION

NOCHILDRENFOREPHEMERALS

NODEEXISTS

NOTEMPTY

SESSIONEXPIRED

INVALIDCALLBACK

INVALIDACL

AUTHFAILED

CLOSING

NOTHING

SESSIONMOVED

Methods

__construct(string $host = '', callable $watcher_cb = null, int $recv_timeout = 10000)

Create a handle to used communicate with zookeeper.

connect(string $host, callable $watcher_cb = null, int $recv_timeout = 10000)

Create a handle to used communicate with zookeeper.

close()

Close the zookeeper handle and free up any resources.

string
create(string $path, string $value, array $acl, int $flags = null)

Create a node synchronously.

bool
delete(string $path, int $version = -1)

Delete a node in zookeeper synchronously.

bool
set(string $path, string $data, int $version = -1, array $stat = null)

Sets the data associated with a node.

string
get(string $path, callable $watcher_cb = null, array $stat = null, int $max_size = 0)

Gets the data associated with a node synchronously.

array|false
getChildren(string $path, callable $watcher_cb = null)

Get children data of a path.

bool
exists(string $path, callable $watcher_cb = null)

Checks the existence of a node in zookeeper synchronously.

array
getAcl(string $path)

Gets the acl associated with a node synchronously.

bool
setAcl(string $path, int $version, array $acls)

Sets the acl associated with a node synchronously.

int
getClientId()

return the client session id, only valid if the connections is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE).

bool
setWatcher(callable $watcher_cb)

Set a watcher function.

int
getState()

Get the state of the zookeeper connection.

int
getRecvTimeout()

Return the timeout for this session, only valid if the connections is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE). This value may change after a server reconnect.

bool
addAuth(string $scheme, string $cert, callable $completion_cb = null)

Specify application credentials.

bool
isRecoverable()

Checks if the current zookeeper connection state can be recovered.

bool
setLogStream(resource $file)

Sets the stream to be used by the library for logging.

static bool
setDebugLevel(int $level)

Sets the debugging level for the library.

static bool
setDeterministicConnOrder(bool $trueOrFalse)

Enable/disable quorum endpoint order randomization.

Details

__construct(string $host = '', callable $watcher_cb = null, int $recv_timeout = 10000)

Create a handle to used communicate with zookeeper.

If the host is provided, attempt to connect.

Parameters

string $host
callable $watcher_cb
int $recv_timeout

Exceptions

ZookeeperException
ZookeeperConnectionException

connect(string $host, callable $watcher_cb = null, int $recv_timeout = 10000)

Create a handle to used communicate with zookeeper.

Parameters

string $host
callable $watcher_cb
int $recv_timeout

Exceptions

ZookeeperException
ZookeeperConnectionException

close()

Close the zookeeper handle and free up any resources.

string create(string $path, string $value, array $acl, int $flags = null)

Create a node synchronously.

Parameters

string $path
string $value
array $acl
int $flags

Return Value

string

Exceptions

ZookeeperException
ZookeeperNoNodeException

bool delete(string $path, int $version = -1)

Delete a node in zookeeper synchronously.

Parameters

string $path
int $version

Return Value

bool

Exceptions

ZookeeperException
ZookeeperNoNodeException

bool set(string $path, string $data, int $version = -1, array $stat = null)

Sets the data associated with a node.

Parameters

string $path
string $data
int $version
array $stat

Return Value

bool

Exceptions

ZookeeperException
ZookeeperNoNodeException

string get(string $path, callable $watcher_cb = null, array $stat = null, int $max_size = 0)

Gets the data associated with a node synchronously.

Parameters

string $path
callable $watcher_cb
array $stat
int $max_size

Return Value

string

Exceptions

ZookeeperException
ZookeeperNoNodeException

array|false getChildren(string $path, callable $watcher_cb = null)

Get children data of a path.

Parameters

string $path
callable $watcher_cb

Return Value

array|false

Exceptions

ZookeeperException
ZookeeperNoNodeException

bool exists(string $path, callable $watcher_cb = null)

Checks the existence of a node in zookeeper synchronously.

Parameters

string $path
callable $watcher_cb

Return Value

bool

Exceptions

ZookeeperException

array getAcl(string $path)

Gets the acl associated with a node synchronously.

Parameters

string $path

Return Value

array

Exceptions

ZookeeperException

bool setAcl(string $path, int $version, array $acls)

Sets the acl associated with a node synchronously.

Parameters

string $path
int $version
array $acls

Return Value

bool

Exceptions

ZookeeperException

int getClientId()

return the client session id, only valid if the connections is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE).

Return Value

int

Exceptions

ZookeeperException
ZookeeperConnectionException

bool setWatcher(callable $watcher_cb)

Set a watcher function.

Parameters

callable $watcher_cb

Return Value

bool

Exceptions

ZookeeperException
ZookeeperConnectionException

int getState()

Get the state of the zookeeper connection.

Return Value

int

Exceptions

ZookeeperException
ZookeeperConnectionException

int getRecvTimeout()

Return the timeout for this session, only valid if the connections is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE). This value may change after a server reconnect.

Return Value

int

Exceptions

ZookeeperException
ZookeeperConnectionException

bool addAuth(string $scheme, string $cert, callable $completion_cb = null)

Specify application credentials.

Parameters

string $scheme
string $cert
callable $completion_cb

Return Value

bool

Exceptions

ZookeeperException
ZookeeperConnectionException

bool isRecoverable()

Checks if the current zookeeper connection state can be recovered.

Return Value

bool

Exceptions

ZookeeperException
ZookeeperConnectionException

bool setLogStream(resource $file)

Sets the stream to be used by the library for logging.

TODO: might be able to set a stream like php://stderr or something

Parameters

resource $file

Return Value

bool

static bool setDebugLevel(int $level)

Sets the debugging level for the library.

Parameters

int $level

Return Value

bool

static bool setDeterministicConnOrder(bool $trueOrFalse)

Enable/disable quorum endpoint order randomization.

Parameters

bool $trueOrFalse

Return Value

bool