Question: I can't find this in the docs or by searching, maybe someone has some tips. I'm trying to check how many connections are on a presence channel on the backend.

I can check fine on the front-end with Echo like so:

```
Echo.join('chat')
    .here((users) => {
        // users.length is the proper count of connections
    })

```

But is there a way I can get that same number of connections, but in the backend code somewhere within Laravel?

Answer: 
If you are using Pusher, the backend can just do the following:

```
$response = $pusher->get( '/channels/presence-channel-name/users' );
if( $response[ 'status'] == 200 ) {
  // convert to associative array for easier consumption
  $users = json_decode( $response[ 'body' ], true )[ 'users' ];
}

$userCount = count($users);

```

You can read more about it in the pusher [documentation](https://pusher.com/docs/server_api_guide/interact_rest_api#presence-users). The [pusher-http-php](https://pusher.com/docs/server_api_guide/interact_rest_api#presence-users) sdk also has some documentation for this.

> 
> A list of users present on a presence channel can be retrieved by
>  querying the `/channels/[channel_name]/users` resource where the
>  `channel_name` is replaced with a valid presence channel name.
> 
> 
> 

This is explicitly *only* for presence channels.

Additionally, you can keep track of users in channels through [webhooks](https://pusher.com/docs/webhooks#presence). 

> 
> Notify your application whenever a user subscribes to or unsubscribes
>  from a Presence channel.
>  For example, this allows you to synchronise channel presence state on
>  your server as well as all your application clients.
> 
> 
> 

Pusher will hit your server with information in the following form:

```
{
  "name": "member_added", // or "member_removed"
  "channel": "presence-your_channel_name",
  "user_id": "a_user_id"
}

```

This data could potentially be stored in a table in your database or alternatively in redis.
I don't think it's possible. The channels are between the client (website with JS) and the WebSocket-Server (own NodeJS-Server or the Pusher-Servers). Laravel is just pushing events to them but is never pulling.

To find a solution we have to know which driver you are using (redis or pusher). It's maybe possible to ask the pusher server with curl how many users are on the server.

For pusher this looks interesting: <https://support.pusher.com/hc/en-us/articles/204113596-Showing-who-s-online-with-a-large-number-of-users> and <https://pusher.com/docs/rest_api#method-get-channels>

For Redis you could implement some logic inside the NodeJS server to listen to the channels and fire a request to laravel.

The best solution to be independent is to fire a request from each client to update the counter in your database:

```
Echo.join('chat')
.here((users) => {
    //request to laravel api with users.length
})

```

The disadvantage of this method is, that it only updates the value when a user connects to the channel