nchan_eventsource_ping_event

Sets the ping event interval for EventSource connections in Nginx's Nchan module.

Syntaxnchan_eventsource_ping_event interval;
Defaultnone
Contextserver, location, if in location
Arguments1

Description

The nchan_eventsource_ping_event directive configures the interval at which ping events are sent to clients for EventSource (SSE) connections. This is particularly important in maintaining an open connection with clients, helping to prevent timeouts due to inactivity. Setting the directive allows administrators to specify how often the server should send a ping event to connected EventSource clients, ensuring they remain aware of the connection's status.

When specified, the value set in nchan_eventsource_ping_event defines the frequency of these ping messages in seconds. If a client does not send a message within the set time frame or if the server does not receive communication, the connection may be considered stale and closed, which is why proper configuration of this directive is essential for applications relying on real-time data delivery. The ping mechanism is particularly useful for long-lived connections, aligning the server and client interaction more closely, and ensuring that both can detect disconnections promptly.

To implement nchan_eventsource_ping_event, you can include it in your Nginx configuration files within the server or location context. Ensure that you set it appropriately based on your application's needs, taking into consideration the balance between resource usage and connection stability for users.

Config Example

server {
    location /events {
        nchan_eventsource_ping_event 30;
        nchan_pubsub;
    }
}

Setting the ping interval too low may lead to unnecessary load on the server due to frequent ping messages.

If the ping interval is too high, clients might experience disconnections due to timeout from intermediate proxies or firewalls.

← Back to all directives