0

I am using laravel 5.1 and I want to know how many clients are listening to a particular channel say Test-Channel. I want this number on server? Is there any way I can get it? Further I am using Broadcasting with Redis.

The link to broadcasting document is as follows:

Laravel 5.1 Event Broadcasting

Laurence
  • 58,936
  • 21
  • 171
  • 212
Hassan Saqib
  • 2,597
  • 7
  • 28
  • 51

1 Answers1

1

There is command for this in redis. Check out PUBSUB NUMSUB:

Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.

And PUBSUB NUMPAT:

Returns the number of subscriptions to patterns (that are performed using the PSUBSCRIBE command). Note that this is not just the count of clients subscribed to patterns but the total number of patterns all the clients are subscribed to.

Edit: It's also worth noting that the PUBLISH command also returns number of receivers:

Return value

Integer reply: the number of clients that received the message.

Linus Thiel
  • 38,647
  • 9
  • 109
  • 104
  • Thanks @Linus... Do you know how to use it in laravel 5.1? – Hassan Saqib Jun 14 '15 at 13:35
  • I'm not at all familiar with Laravel, but if I understand it correctly you have to roll part of the redis setup yourself anyway? Lavarel or not, you should just be able to issue that command to the redis server directly, using the predis client or such. – Linus Thiel Jun 15 '15 at 07:19