Disruption to common sense-code with an endless loop structure, and the opportunity to execute logic outside the loop
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 ('2017. 0.0.1: 100 ');
$ Zoo-> get ('/test', array ($ zoo, 'Watcher '));
While (true ){
Echo '.';
Sleep (2 );
}
Run the script now.
$ Php zookeeperdemo1.php
A vertex is generated every 2 seconds. Switch to the ZooKeeper client and update the "/test" value.
[Zk: 127.0.0.1: 2181 (CONNECTED) 20] set/test foo
This will silently trigger the "Insider Watcher" message in the PHP script.
How can this happen? Why can I execute the watcher method after entering the while structure. Please read the official discussion.
Reply to discussion (solution)
Distributed applications?
ZooKeeper is a distributed, open-source distributed application coordination service that contains a simple primitive set and is an important component of Hadoop and Hbase. Currently, Java and C interfaces are provided.
It is understandable that you say it is a common sense of disruption.
Instead of distributed, distributed is just what my business needs.
What's about disruption is --
In PHP, the structure of the endless loop has the opportunity to execute the logic that is obviously unrelated to the Loop-this is the performance of multithreading-so we guess this zookeeper extension runs in the php environment in a multi-thread way.
Watcher gets consumed so we need to set a new one
You should be more aware of this than I do.
Php Zookeeper is always listening for php behavior
I am just planning to do this.
I mean, isn't it strange if someone writes and debugs a piece of php code and finds that there is a chance to execute code that is completely irrelevant to the loop in the endless loop process?
Isn't it normal that the subthread continues to execute tasks in an endless loop of the main thread?
There is a pcntl in php that can fork multiple processes for execution.
Certainly not fork