Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aks2193 opened this issue Feb 15, 2024 · 0 comments
Open

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

aks2193 opened this issue Feb 15, 2024 · 0 comments

Comments

@aks2193
Copy link

aks2193 commented Feb 15, 2024

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.

@aks2193 aks2193 changed the title Trying to execute multiple zmq send in same event loop Execute multiple zmq send in same event loop Feb 15, 2024
@aks2193 aks2193 changed the title Execute multiple zmq send in same event loop Execute multiple zmq send in same event loop with php ratchet Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant