Closed ifeelcold1999 closed 8 years ago
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'); } }
Running this in php-5.6.14 thread safety disabled, get($path , $watch_cb) and set($path, $value) work fine, but the get_watch_cb function never works.
This is very similar with https://github.com/andreiz/php-zookeeper/issues/34, but my php is thread safety disabled, so it doesn't have much help.
I find the key! I didn't add a while(true) in my code, so everything includes the watcher is gone when the request is finished.
while(true)
Running this in php-5.6.14 thread safety disabled, get($path , $watch_cb) and set($path, $value) work fine, but the get_watch_cb function never works.
This is very similar with https://github.com/andreiz/php-zookeeper/issues/34, but my php is thread safety disabled, so it doesn't have much help.