nchan_eventsource_ping_interval
Sets the interval for sending ping messages to clients using EventSource connections.
Description
The nchan_eventsource_ping_interval directive specifies the time interval at which ping messages are sent over EventSource connections to keep the connection alive. When clients are connected through EventSource, the server maintains an open connection to push updates to the clients. If the connection is idle for a while, clients may disconnect, so sending periodic ping messages ensures that the connection remains active and functional. This directive accepts a single argument, which is a time value that indicates the interval between successive pings to the client.
In practice, this directive can help maintain the connection health with minimal client interaction. Depending on the value provided, you can configure the frequency of these pings to strike a balance between resource usage and connection availability. For instance, setting a shorter interval may prevent disconnections due to network issues but can also lead to increased load on both the server and client. Conversely, a longer interval may save resources but increase the risk of silent disconnections.
This directive is especially useful when building real-time applications that depend on keeping WebSockets or EventSource connections open without interruption during high load or idle periods. It can be used in various contexts such as server, location, and even within if conditions inside a location block, thereby providing flexibility depending on your application’s specific needs.
Config Example
location /events {
nchan_eventsource_ping_interval 30s;
nchan_subscriber_channel_id your_channel;
}Setting an excessively low interval can lead to increased server load.
If misconfigured, it might cause clients to disconnect more frequently than necessary.