Answer the question
In order to leave comments, you need to log in
PHP + ZeroMQ, how not to lose messages if PULL worker crashes?
Hello!
I use ZeroMQ with the PUSH-PULL pattern in order to receive a request from the client and instantly send a page about the success of the operation to the browser, and at this time transfer all the "hard" work to the worker.
It looks like this. Customer:
$pusher = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$pusher->bind("tcp://*:5557");
$pusher->send("My message", ZMQ::MODE_DONTWAIT);
$receiver = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$receiver->connect("tcp://localhost:5557");
while (true) {
$string = $receiver->recv();
// ...
}
Answer the question
In order to leave comments, you need to log in
Maybe you should use a persistent queue like RabbitMQ ? There is no size limit for messages and they are saved until they are consumed. Moreover, the message is reserved while the worker is executing the task and is either removed from the queue upon successful completion, or returned to the queue if the worker died quietly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question