我想在PHP應用程序使用的飼養員,我已經完成了大部分的get($path)
/set($path, $value)
/getChildren($path)
功能如下https://github.com/andreiz/php-zookeeper,除了watch_callback
功能是行不通的。PHP飼養員守望不起作用
我的php版本是5.6.14和線程安全禁用,我使用apache2.4。
下面是一些代碼片斷
class Zookeeper_Module {
private $zookeeper;
public function __construct(){
$this->ci = & get_instance();
$zookeeper_server = $this->ci->config->item('zookeeper_server');
$this->zookeeper = new Zookeeper($zookeeper_server);
}
public function set($path, $value){
$this->zookeeper->set($path, $value);
}
public function get($path, $watch_cb = null){
return $this->zookeeper->get($path, $watch_cb);
}
public function get_watch_cb($event_type = '', $stat = '', $path = ''){
error_log('hello from get_watcher_cb');
$value = $this->get($path, array($this, 'get_watch_cb'));
// update redis cache
$this->ci->cache->redis->save('some cache key', $value);
}
}
class MyTest{
public function get(){
$zookeeper = new Zookeeper_Module();
$value = $zookeeper->get('/foo/bar', array (
$zookeeper,
'get_watch_cb'
));
}
public function set(){
$zookeeper = new Zookeeper_Module();
$zookeeper->set('/foo/bar', 'some value');
}
}
我可以成功地獲取或設置一個節點的值,但我既不能抓手錶回調日誌也沒有Redis的緩存進行更新。