nchan_eventsource_ping_data

The `nchan_eventsource_ping_data` directive specifies the data payload sent during keep-alive pings to subscribers using the EventSource protocol.

Syntaxnchan_eventsource_ping_data data;
Defaultnone
Contextserver, location, if in location
Arguments1

Description

The nchan_eventsource_ping_data directive is utilized within Nchan, a scalable pub/sub server module used in NGINX to facilitate real-time notifications and interactions among numerous concurrent connections. When enabled in a suitable context, this directive defines what data is sent during the EventSource keep-alive pings. This particular functionality ensures that the connection between the client and server remains active, preventing timeouts and allowing the server to push updates to the client without needing a continuous request-response cycle.

By configuring this directive, users can customize the payload of the pings, which can serve multiple purposes such as health checks, providing version identifiers, or sending metadata that the client can use without requiring additional round-trips to the server. The directive's argument is expected to be a data string which defines the content of the ping data. Properly leveraging this directive can significantly improve user experience by keeping the communication channel alive and providing useful data.

The directive can be configured under various contexts including server, location, or conditional within a location. This flexible application offers developers the ability to optimize their server's behavior depending on the specific needs of different routes or responder conditions.

Config Example

location /events {
    nchan_eventsource_ping_data '{"ping": "keep-alive"}';
    # Other Nchan configurations...
}

Ensure the ping data format is valid JSON if you are sending structured data.

Be cautious of the frequency of the ping; setting it too low can lead to unexpected load on the server.

← Back to all directives