Server-sent push notifications (FCM HTTP v1, Web Push, ntfy)
pushfcmfirebaseweb-pushvapidntfyphpnotifications
Ways a PHP server on Justin's box pushes alerts to phones, as built for the guardian parent alerts and observed in tldr's push system.
Options compared (parent alerts for the kid phone)
- ntfy: simplest server side, but the parent needs another app. Code present, left unconfigured.
- Web Push (VAPID): works from the browser portal with no app; good fallback.
- SMS from the kid phone, email: offered, not chosen.
- A WebView shell app: rejected by Justin ("feels cheap").
- Native parent mode in the existing app with FCM: chosen. Delivery order on the server: FCM, then web push, then ntfy.
FCM HTTP v1 from PHP
- Add the new Android package to an existing Firebase project (here the tldr project) and reuse the same service-account JSON on the server; no new project needed. The app gets its own
google-services.json. - Mint an OAuth access token from the service account (JWT,
https://www.googleapis.com/auth/firebase.messagingscope), cache it in the database until near expiry, then POST tohttps://fcm.googleapis.com/v1/projects/<id>/messages:send. - A quick live check: a send to a fake token returns 400 from Google, which proves the OAuth path works.
- Use separate notification channels per severity on the Android side.
- Devices without Google Play Services: disable FCM auto-init in the manifest and guard initialization on Play Services availability, so the same APK runs inert on a de-Googled phone.
Web Push
minishlink/web-push9.x works without thegmpextension; it can be deployed as a plainvendor/directory.- Generate VAPID keys once and keep them in a server-only config (owned by apache, mode 0640). Regenerating them invalidates every existing subscription; protect the generator with a
--forceflag. - Serve the service worker (
sw.js) from the portal path.
Lessons from tldr's push system (post #1726)
- All pushes shared one Android notification tag, so a later push replaced an earlier one in the tray and the user never saw the first. Use a per-thread or per-post tag.
- AI answers wrote no in-app inbox row, so a replaced push left no trace. Push should be a pointer to something persistent.
- The send result was discarded (
curl_execunchecked), so delivery could not be proven. Log the response and prune tokens that FCM reports as unregistered; stale test tokens had accumulated.
Rate and collapse
Collapse alerts per category per hour on the server, and make event ingestion idempotent with a client-generated UUID so retries do not double-alert.
See also
- Locking down an Android phone with a device-owner app
- TLDR platform architecture (tldrnerd.com)
- FCM push notifications from a PHP backend to a Flutter app (Flutter client side, deep links, throttling, visibility rules)