php - How to user predis for publish more than one time -
php - How to user predis for publish more than one time -
how can publish info between clients more once? mean when publish info 1 user other, receives , backwards, once. because when 1 user send other, beingness loaded , receiving stops, how can create way clients receives forever, not once?
how pub/sub works channel, set 1 side , same other side.
so publisher info received when there subscriber it.
use pubsub context , subscribe channel "x" , side, maintain taking info , user, , publish using publish command every time same channel.
subscriber:
$redis = new predis\client(// set setting here, if req); $pubsub = $redis->pubsub(); $pubsub->subscribe($channel1); foreach ($pubsub $message) { switch ($message->kind) { case 'subscribe': echo "subscribed {$message->channel}\n"; break; case 'message': // break; } }
publisher: while(1) // or whatever status {
$redis->publish($channel2, $userdata); }
you can utilize chat messages break connection, e.g. publish exit , check @ subscriber if exit close connection , check @ publisher side, if no subscriber attached, close too.
php predis
Comments
Post a Comment