Skip to content

Execute multiple zmq send in same event loop with php ratchet #1057

Open
@aks2193

Description

Hey,

I have a list of 500 results that I want to send from my zmq worker class to my server class. Now I am trying to send the first 50 results and then do some processing for the next 450 results and then send them on the same zmq socket. But what i see is on the server side I am getting both the response together. I was expecting that the first 50 results will reach server and the server can send it to client and when it gets the other 450 results it can then send it back to client. Below is the code that I use

Server Code File

$loop = \React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$pusher = $context->getSocket(ZMQ::SOCKET_PUSH);
$pusher->bind("tcp://127.0.0.1:8889");
$applicationObj = new ServerApplication($pusher);

$sink = $context->getSocket(ZMQ::SOCKET_PULL);
$sink->bind("tcp://127.0.0.1:8888");

$sink->on("message", function ($message) use ($applicationObj) {
    TODO: SEND MESSAGE TO CLIENT
});

$webSock = new React\Socket\Server($loop);
$webSock->listen($options["serverport"], "0.0.0.0"); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
    new Ratchet\Http\HttpServer(
        new Ratchet\WebSocket\WsServer($applicationObj)
    ),
    $webSock
);

$loop->run();

Worker Code File

$loop = \React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);

$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->connect('tcp://127.0.0.1:8889');

$push = $context->getSocket(ZMQ::SOCKET_PUSH);
$push->connect('tcp://127.0.0.1:8888');


$pull->on('message', function($message) use ($loop, $push) {
        $response = []; (this is an array of initial 50 results)
        $push->send($response);
        $next_res = get_next_450_results();
        $new_resp = [];  (this is array of next 450 results)
        $push->send($new_resp)
});
$loop->run();

Can someone please help me with the issue here, basically I am not able to send the response from worker to server in paginated way.
I am using php ratchet and zmq.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions