Skip to content

Commit

Permalink
Merge pull request #164 from pusher/how-to-get-channels-with-subscrip…
Browse files Browse the repository at this point in the history
…tion-counts

How to get a list of application channels with subscription counts
  • Loading branch information
WillSewell committed Oct 18, 2018
2 parents 540bbe5 + 6132393 commit ad6503a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions README.md
Expand Up @@ -224,7 +224,7 @@ Note: this assumes that you store your users in a table called `users` and that
$pusher->get_channel_info( $name );
```

It's also possible to get information about a channel from the Pusher REST API.
It's also possible to get information about a channel from the Pusher HTTP API.

```php
$info = $pusher->get_channel_info('channel-name');
Expand All @@ -251,7 +251,7 @@ $subscription_count = $info->subscription_count;
$pusher->get_channels()
```

It's also possible to get a list of channels for an application from the Pusher REST API.
It's also possible to get a list of channels for an application from the Pusher HTTP API.

```php
$result = $pusher->get_channels();
Expand All @@ -277,6 +277,21 @@ This can also be achieved using the generic `pusher->get` function:
$pusher->get( '/channels', array( 'filter_by_prefix' => 'presence-' ) );
```

### Get a list of application channels with subscription counts

The HTTP API returning the channel list does not support returning the subscription count along with each channel. Instead, you can fetch this data by iterating over each channel and making another request. But be warned: this approach consumes (number of channels + 1) messages!

```php
<?php
$subscription_counts = array();
foreach ($pusher->get_channels()->channels as $channel => $v) {
$subscription_counts[$channel] =
$pusher->get_channel_info(
$channel, array('info' => 'subscription_count'))->subscription_count;
}
var_dump($subscription_counts);
```

### Get user information from a presence channel

```php
Expand Down Expand Up @@ -310,9 +325,9 @@ Array
$pusher->get( $path, $params );
```

Used to make `GET` queries against the Pusher REST API. Handles authentication.
Used to make `GET` queries against the Pusher HTTP API. Handles authentication.

Response is an associative array with a `result` index. The contents of this index is dependent on the REST method that was called. However, a `status` property to allow the HTTP status code is always present and a `result` property will be set if the status code indicates a successful call to the API.
Response is an associative array with a `result` index. The contents of this index is dependent on the HTTP method that was called. However, a `status` property to allow the HTTP status code is always present and a `result` property will be set if the status code indicates a successful call to the API.

```php
$response = $pusher->get( '/channels' );
Expand Down

0 comments on commit ad6503a

Please sign in to comment.