Realtime
Realtime uses Server-Sent Events: a one-way HTTP stream, supported by all browsers, that works through shared hosting and proxies. Each connection is held up to 55 s then transparently reconnected with a cursor — you never miss an event.
SDK
const stop = app.db.collection("chat")
.where("room", "==", "general").orderBy("createdAt").limit(100)
.onSnapshot((docs, event) => {
// docs: full current array (kept up to date locally)
// event: { type: "snapshot" | "create" | "update" | "delete" | "drop", id, doc }
}, err => console.error(err));
app.db.collection("games").doc("g1").onSnapshot(doc => { /* doc or null */ });
stop(); // unsubscribeBehaviour: first callback is a full fetch (snapshot). Subsequent changes are applied locally. Filtered queries re-fetch when a new document may match.
REST / other languages
# stream
GET /v1/{pid}/realtime/chat?key=cb_pk_…&token=<jwt>&since=<cursor>
event: ready data: {"cursor":120}
event: change data: {"seq":121,"type":"create","id":"…","doc":{…},"at":"…"}
event: reconnect data: {"cursor":130}
# polling (for Flutter/PHP etc.)
GET /v1/{pid}/realtime/chat?poll=1&since=120 -> { events:[…], cursor: 130 }Limits
Realtime respects the collection's read rule. Change history is retained ~24 h. Free plan includes realtime (see plans). Each open stream occupies one PHP worker — keep a few streams per user, not dozens.
Was this page helpful? Tell us. · Download SDK