1
我已經在PHP中實現了0mq呼吸機/工人/接收器示例。呼吸機向工作人員發送消息。工作人員收到這些消息並將結果發送到接收器。PHP 0mq接收器沒有收到消息
工人正確接收消息,但接收器從未收到他們的迴應。我究竟做錯了什麼?
在Virtualbox VM中使用PHP 5.5.9-1ubuntu4.9和libzmq v2.2.0。
呼吸機:
$context = new ZMQContext();
$sender = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$sender->bind('tcp://*:5557');
echo 'Sending IDs to workers...', PHP_EOL;
for ($i = 0; $i < 100; $i ++) {
$sender->send($i);
}
工人:
$context = new ZMQContext();
$receiver = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$receiver->connect('tcp://localhost:5557');
$sender = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$sender->connect('tcp://localhost:5558');
while (true) {
$i = $receiver->recv();
echo 'Processing ', $i, PHP_EOL;
$sender->send($i * 2);
}
水槽:
$context = new ZMQContext();
$receiver = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$receiver->connect('tcp://*:5558');
echo 'Receiving rows from workers...', PHP_EOL;
while (true) {
$result = $receiver->recv();
echo $result, PHP_EOL;
}
結果:
工人說 '加工0 - 99 ......' 但沉沒有顯示輸出。
預期:
水槽輸出0,2,4,6,8,等等