andreiz / php-zookeeper

A PHP extension for interfacing with Apache ZooKeeper
Other
449 stars 215 forks source link

get with a watcher could not invoke the watcher callback #34

Open haiwenzhu opened 10 years ago

haiwenzhu commented 10 years ago
class ZookeeperDemo extends Zookeeper {

    public function watcher( $i, $type, $key ) { 
        echo "Insider Watcher\n";

        // Watcher gets consumed so we need to set a new one
        $this->get( '/bar', array($this, 'watcher' ) );
    }   

}

$zoo = new ZookeeperDemo('127.0.0.1:2181');
$zoo->set('/bar', 1); 
$zoo->get( '/bar', array($zoo, 'watcher') );

while( true ) { 
    echo '.';
    sleep(2);
}

running this in php-5.5.6 will report a php warning: PHP Warning: Unknown: could not invoke watcher callback in Unknown on line 0

haiwenzhu commented 10 years ago

It seems that php must be thread safety disabled to make wathcer work. I turned my php from thread safety to no-safety and this problem is fixed.

Timandes commented 6 years ago

Would you try new function zookeeper_dispatch()?