How are connections counted?

The connection count on pricing plans indicates the number of simultaneous connections allowed.

A connection is counted as a WebSocket connection to Pusher. When using the Pusher JavaScript library a new WebSocket connection is created when you create a new Pusher instance.

var pusher = new Pusher('APP_KEY');

Channel subscriptions are created over the existing WebSocket connection (known as multiplexing), and do not count towards your connection quota (there is no limit on the number allowed per connection).

var channel1 = pusher.subscribe('ch1');
var channel2 = pusher.subscribe('ch2');

// All done over as single connection

// more subscriptions
// ...

var channel 100 = pusher.subscribe('ch100');

// Still just a 1 connection

Common reasons why connections are higher than expected

Users open multiple tabs

If a user has multiple tabs open to the same application, multiple instances of Pusher will be created and therefore multiple connections will be used e.g. 2 tabs open will mean 2 connections are established.

Incorrectly coded applications

As mentioned above, a new connection is created every time a new Pusher object is instantiated. It is therefore possible to create many connections in the same page.

Using an older version of one our libraries

Our connection strategies have improved over time, and we recommend that you keep up to date with the latest versions.

Specifically, in newer versions of our JS library, we carry out ping-pong requests between server and client to verify that the client is still around.

Other remedies

While our efforts are always to keep a connection going indefinitely to an application, it is possible to disconnect manually if you feel this works in your scenario. It can be achieved by making a call to `Pusher.disconnect()`. Below is some example code:

 

var pusher = new Pusher("APP_KEY");
var timeoutId = null;
function startInactivityCheck() {
    timeoutId = window.setTimeout(function(){
        pusher.disconnect();
    }, 5 * 60 * 1000); // called after 5 minutes
};

// called by something that detects user activity
function userActivityDetected(){
    if(timeoutId !== null) {
        window.clearTimeout(timeoutId);
    }

    startInactivityCheck();
};

How this disconnection is trasmitted to the user is up to you but you may consider prompting them to let them know that they will not receive any further real-time updates due to a long period of inactivity. If they wish to start receiving real-time updates again they should click a button.

Was this article helpful?
6 out of 6 found this helpful
Haven't found what you were looking for?
Submit a ticket