Skip to content
Tranch edited this page Aug 15, 2016 · 2 revisions

Welcome to the php-zookeeper wiki!

<?php

/**
 * PHP Zookeeper
 * YuChao php access zookeeper library
 *
 * @category  Libraries
 * @package   EdjYuChao
 * @author    Yu Chao<yuchao@YuChao-inc.cn>
 * @copyright YuChao GPL
 * @license   http://www.php.net/license The PHP License, version 3.01
 */
class EdjZkWatcher extends Zookeeper
{

    private $path = '/YuChao';

    public function watcher($i, $type, $key)
    {
        echo "Insider Watcher $i,'|',$type,'|',$key\n";
        $this->path = $key;

        // Watcher gets consumed so we need to set a new one
        $newvalue = $this->get($this->path, array($this, 'watcher'));
        echo "The Watcher value is:" . $newvalue . "\n";
    }

    public function watch($path, $callback = 'default')
    {
        // path exist
        if ($callback == 'default') {
            $callback = array($this, 'watcher');
        } else {
            $callback = array($this, 'watch');
        }
        $YuChao = $this->get($path, $callback);
        echo "watch is " . $YuChao . "\n";
        return $YuChao;
    }

}

$zoo = new EdjZkWatcher('121.40.173.217:2181');
//$zoo->set("/YuChao","yuchaodemo");
//$YuChao = $zoo->get( '/YuChao', array($zoo, 'watcher' ) );
$watch_YuChao = $zoo->watch('/YuChao/test/page/page_index');
$other = $zoo->watch('/YuChao/test/page/other');

//echo "The YuChao is ".$YuChao;
echo "The YuChao is " . $watch_YuChao;
while (true) {
    echo '.';
    sleep(2);
}

?>
Clone this wiki locally