3. Practice 2. zeromqmdp (MajordomoProtocol) mode test description: 1) zeromqmdp mode. You can go to the guide on the zeromq official website to learn it yourself. However, the structure of the mdp mode should be mentioned as follows: 2) test environment description (zmq library and czmq Library have been installed by default, and zm has been added in php.
3. Practice 2. zeromq mdp (Majordomo Protocol) mode test description: 1) zeromq mdp mode you can go to the guide on the zeromq official website to learn about it. However, the structure of the mdp mode should be mentioned as follows: 2) test environment description (zmq library and czmq Library have been installed by default, and zm has been added in php.
Iii. Practice
2. zeromq mdp (Majordomo Protocol) mode test
Note:
1) In zeromq mdp mode, you can go to the guide on the zeromq official website to learn about it.
However, the structure of the mdp mode should be described as follows:
2) test environment description (zmq library and czmq Library have been installed by default, and zmq components have been added in php .)
The mdp architecture is divided into three parts:
A) client: php implementation
B) broker: C implementation
C) worker: C implementation
Client code: mdclient. php
Copyright Description: This code is a test code on the ZMQ official website and may have been modified;
I will not post all the code here. It is actually the test code on the zmq official website, and some simple modifications have been made;
If anyone needs it or has encountered any problems during the test, they can directly comment on it and we will discuss it together.
*/include_once 'mdcliapi.php';$verbose = $_SERVER['argc'] > 1 && $_SERVER['argv'][1] == '-v';$session = new MDCli("tcp://localhost:5555", $verbose);for ($count = 0; $count < 10; $count++) { $request = new Zmsg(); $request->body_set("Hello world from php client"); $reply = $session->send("echo", $request); if (!$reply) { break; // Interrupt or failure }}printf ("%d requests/replies processed", $count);echo PHP_EOL;?>
Test result (client ):
Test result (broker ):
Test result (worker ):
Test result analysis:
1) Send the string "Hello world from php client" from the client (php ";
2) broker routing (the broker does not enable the debugging switch, so the printing process is not visible );
3) finally sent to worker.
Problems encountered during the test:
In the preceding example, the client only sends the message but does not receive the message. If you use the mdclient2.php code to test, the worker and broker use c, and send multiple frames of data, you will find that the client parsing will encounter errors. After investigation, this is because the php client does not parse one frame when receiving the message.
Iv. Summary
[Linux + lighttpd + php + zeromq] This architecture, from environment setup to two small examples, has been completed. I believe that if you have practiced it, you should get started. If you want to apply this architecture to a real project, there may be many ways to go. If you have any questions, you can discuss and exchange them on this blog.
A life without goals or dreams is terrible and boring!
Your life tomorrow is determined by today!