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 ('/test ', Array ($this, ' Watcher '));
}
}
$zoo = new Zookeeperdemo (' 127.0.0.1:2181 ');
$zoo->get ('/test ', Array ($zoo, ' Watcher '));
while (true) {
echo '. ';
Sleep (2);
}
Now run the script.
$ PHP zookeeperdemo1.php
This should produce a point every 2 seconds. Now switch to the Zookeeper client and update the "/test" value.
[Zk:127.0.0.1:2181 (CONNECTED)] set/test foo
This will silently trigger the "insider Watcher" message in the PHP script.
How did that happen? Why the Watcher method can be executed after entering the while structure. Please crossing to discuss the issue.
Reply to discussion (solution)
Distributed applications?
Zookeeper is a distributed, open-source, distributed application Coordination service that contains a simple set of primitives and is an important component of Hadoop and HBase. Currently, Java and C interfaces are available.
It's understandable, you say, to subvert common sense.
It's not about the distribution, it's just my business needs.
The place of subversion is--
In PHP, the structure of the dead loop has the opportunity to perform a loop-independent logic outside of the loop--this is the performance of multithreading--and we suspect that the zookeeper extension is running in a multithreaded manner in a PHP environment.
Watcher gets consumed so we need to set a new one
You should know more about this than I do.
PHP Zookeeper is always listening to PHP behavior
I'm not doing this, I'm just going to do this.
I mean, wouldn't it be strange to have someone write debugging a PHP code and find that there is a chance to execute code that doesn't really matter to the loop in the process of a dead loop?
Is it not normal for a child thread to continue to perform a task in the main thread's dead loop?
There's a pcntl in PHP that can fork out a multi-process execution.
Definitely not fork.