
If the connection to the server is lost, the browser will wait for the specified time before attempting to reconnect. The event ID to set the EventSource object's last event ID value. When the EventSource receives multiple consecutive lines that begin with data:, it concatenates them, inserting a newline character between each one. The onmessage handler is called if no event name is specified for a message. If this is specified, an event will be dispatched on the browser to the listener for the specified event name the website source code should use addEventListener() to listen for named events. client closes the page).Įach message received has some combination of the following fields, one per line: eventĪ string identifying the type of event described.

To break the loop if the connection has been closed (e.g. The loop will keep running independent of the connection status, so a check is included At random intervals, a simple message (with no event type) is sent. Each event's data is a JSON object containing the ISO 8601 timestamp corresponding to the time at which the event was generated. The code above generates an event every second, with the event type "ping".

Php date_default_timezone_set ( "America/New_York" ) header ( "Cache-Control: no-store" ) header ( "Content-Type: text/event-stream" ) $counter = rand ( 1, 10 ) while ( true )
