zookeeper_dispatch
(PECL zookeeper >= 0.4.0)
zookeeper_dispatch — Calls callbacks for pending operations
説明
The zookeeper_dispatch() function calls the callbacks passed by operations like Zookeeper::get() or Zookeeper::exists().
Since version 0.4.0, this function must be called manually to achieve asynchronous operations. If you want that to be done automatically, you also can declare ticks at the beginning of your program.
After PHP 7.1, you can ignore this function. This extension uses EG(vm_interrupt) to implement async dispatch.
パラメータ
この関数にはパラメータはありません。
戻り値
値を返しません。
エラー / 例外
This method emits PHP warning when callback could not be invoked.
例
例1 zookeeper_dispatch() example #1
Dispatch callbacks manually.
<?php
$client = new Zookeeper();
$client->connect('localhost:2181');
$client->get('/zookeeper', function() {
echo "Callback was called".PHP_EOL;
});
while(true) {
sleep(1);
zookeeper_dispatch();
}
?>
例2 zookeeper_dispatch() example #2
Declare ticks.
<?php
declare(ticks=1);
$client = new Zookeeper();
$client->connect('localhost:2181');
$client->get('/zookeeper', function() {
echo "Callback was called".PHP_EOL;
});
while(true) {
sleep(1);
}
?>
参考
- Zookeeper::addAuth() - Specify application credentials
- Zookeeper::connect() - Create a handle to used communicate with zookeeper
- Zookeeper::__construct() - Create a handle to used communicate with zookeeper
- Zookeeper::exists() - Checks the existence of a node in zookeeper synchronously
- Zookeeper::get() - Gets the data associated with a node synchronously
- Zookeeper::getChildren() - Lists the children of a node synchronously
- Zookeeper::setWatcher() - Set a watcher function