php-zmq icon indicating copy to clipboard operation
php-zmq copied to clipboard

Unexpected ZMQ::SOCKOPT_LINGER behaviour

Open proArtex opened this issue 7 years ago • 0 comments
trafficstars

According to zmq doc ZMQ_LINGER: "The value of 0 specifies no linger period. Pending messages shall be discarded immediately when the socket is closed with zmq_close()."

So here is my example:

# fpm-script

$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH);
$socket->setSockOpt(ZMQ::SOCKOPT_LINGER, 0);
$socket->connect("tcp://127.0.0.1:5555");
$socket->send('test');
# cli script
$context = new \ZMQContext();
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); 

while (true) {
    var_dump($pull->recv());
}

The magic is random msg delivery (like 1 of 5) while there is not (I guess) zmq_close() call inside fpm-script. And it delivers nothing after cli script rerun that is correct behaviour.

proArtex avatar Aug 24 '18 15:08 proArtex