multithreading - PHP react parallel requests -
i have app communicate through websocket server. using ratchet , works perfect. next thing want implement make requests other server , push responses through websocket clients. question how make parallel requests react. let have 5 endpoints response want parallel (thread). want call each endpoint every .2s example , send response websocket server clients. example (this demonstration code):
$server->loop->addperiodictimer(.2, function ($timer) { curl('endpoint1'); }); $server->loop->addperiodictimer(.2, function ($timer) { curl('endpoint2'); }); $server->loop->addperiodictimer(.2, function ($timer) { curl('endpoint3'); });
but timer not work way. possible achive react?
im not showing websocket code because communication between clients works nice.
to start. "react (ratchet)" - operate in 1 thread mode (feature libevent). is, block process - bad idea... curl request - stop work socket server until receives response.
for application - use zmq. point this:
- you run worker process (for example: zmqworker),
- your server sends curl-data on zmqworker (via zmq).
- zmqworker send curl request
- after sending request, zmqworker send response websocket (via zmq). can via reactphp/zmq
if need send lot of concurrent requests - need pthread library - provides multi-threading.
i've heard possible provide work pthread + libevent, did not do.
p.s but use of architecture zmq, distributed architecture, same scalable!
Comments
Post a Comment