Session-counter cross-tab demo

Click +1. Open this URL in a second window — both update live via a WebSocket broadcast scoped to your PHPSESSID. Foundations → Sessions explains the mechanism.

Live counter

starting…

How it works

// Client
const ws = new WebSocket(proto + '//' + host + '/ws/session-counter');
ws.onmessage = e => document.getElementById('session-counter-btn')
                       ?.outerHTML = e.data;

// Server (excerpt — route/learn.php)
use ZealPHP\Learn\Demo;   // broadcast helper lives in a src/ class

$app->route('/api/learn/demo/session-bump', ...
    $html = App::renderToString('/components/_session_counter', ['n' => $n]);
    Demo::ws_session_counter_broadcast($sid, $html);
    return $html;   // for the clicking tab’s htmx swap
);