Skip to content

Live ​

Live updates on Laravel Reverb: new orders, the notification bell, who is editing a post, comments and a customer's orders appear without a reload.

kitloom/live · admins: kitloom/live-filament, kitloom/live-nova

Video lessons ​

Recorded in the Filament admin; the Nova admin works the same way.

Live updates on a kitloom site, through Laravel Reverb. While someone reads a page, what changes elsewhere shows on it without a reload:

  • Comments. A comment approved in the admin, or posted by another visitor and approved at once, appears under the post on every open page.
  • The account. A customer's order that moves on (paid, shipped, completed, refunded, a note for them) and a client's booking that is confirmed, moved or cancelled show in their account at once. The staff member's schedule follows their bookings too.

A visitor sees only what they would see after a reload. The page is told that something changed, never what: it asks the site again with its own visitor's eyes. Nobody's name, email or order is sent to anyone else's browser.

This works on Vue and React themes (Inertia). A Blade theme draws the same page as before and updates on a reload. In the admins: the bell of kitloom/notifications rings the moment a notice comes, the shop's order lists show a new order at once, a post open in two places says who is editing it, and the Assistant's answer can go on in the background. The admin section is kitloom/live-filament or kitloom/live-nova: it shows whether Reverb is running.

What the server needs ​

WhatWhy
A process manager that keeps php artisan reverb:start runningReverb is one long-lived process that holds the browsers' connections. While it is down, pages work as before and update only when reloaded
The PHP extension pcntlReverb stops and restarts cleanly with it. Ubuntu's PHP has it; the official Docker images need docker-php-ext-install pcntl
The web server passing /app on to ReverbBrowsers connect to the site's own address, so nothing else has to be opened or certified

Nothing goes into .env. The keys the site and Reverb share are made from APP_KEY; Reverb's own variables (REVERB_APP_ID, REVERB_APP_KEY, REVERB_APP_SECRET) win when you set them.

php artisan kitloom:deploy-kit writes all of this for your server, platform or Docker when the module is on.

Setting it up ​

Live updates with Laravel Reverb
  1. Switch the module on (Modules screen, or composer require kitloom/live kitloom/live-filament / kitloom/live-nova).
  2. Start Reverb: php artisan reverb:start. Locally, in a terminal next to php artisan serve.
  3. Rebuild the theme once: npm run build. The build adds the listening part (pusher-js loads only on sites with the module).
  4. Open the admin: the "Live" section's badge says running. php artisan live:status says the same on the server and fails while Reverb does not answer.

On your own machine ​

Reverb listens on port 8080. Without a web server passing /app on, tell the browser where it is:

dotenv
VITE_REVERB_HOST=localhost
VITE_REVERB_PORT=8080
VITE_REVERB_SCHEME=http

nginx ​

Inside the site's server { … }. pusher-js connects to /app/<key>; /app/ itself may be a page of the site, and Reverb's HTTP API (/apps) stays on 127.0.0.1:

nginx
location ~ ^/app/[^/]+$ {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_read_timeout 1h;
}

supervisor ​

/etc/supervisor/conf.d/reverb.conf. Change the path, the user and the log file to match the server:

ini
[program:reverb]
process_name=%(program_name)s
command=php /var/www/site/artisan reverb:start --host=127.0.0.1 --port=8080
user=www-data
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/www/site/storage/logs/reverb.log
minfds=10000

minfds raises the number of open files: each browser holds one connection. After a deploy, php artisan reverb:restart lets Reverb pick up the new code.

Settings ​

config/kitloom-live.php (php artisan vendor:publish --tag=kitloom-live-config):

KeyDefaultWhat it does
enabledKITLOOM_LIVE, trueFalse keeps the module installed and sends nothing
server.host, server.port, server.schemeREVERB_HOST, REVERB_PORT, REVERB_SCHEME: 127.0.0.1, 8080, httpWhere the site sends its broadcasts — Reverb on another host or container
server.timeout2Seconds a broadcast waits for Reverb before it is given up; the comment or the order is saved either way
client.host, client.port, client.schemeVITE_REVERB_HOST, VITE_REVERB_PORT, VITE_REVERB_SCHEME: emptyWhere browsers connect; empty — the site's own address
filament.register, nova.registertrueThe "Live" section of each admin

A site that broadcasts through Pusher or Ably keeps it: set BROADCAST_CONNECTION and that service's keys as Laravel describes. The module then only adds the authorisation of private channels, and the theme needs that service's own client.

More than one Reverb server shares its connections through Redis: REVERB_SCALING_ENABLED=true.

For developers ​

A module makes one of its page parts live by implementing Kitloom\Site\Contracts\LivePart: liveOn($page) answers the event whose broadcast refreshes the part on that page, or null. The event is a ShouldBroadcastNow on a channel from Kitloom\WpSchema\Live\LiveChannels (public('post', $id, 'comments'), private('user', $id, 'account')), with nothing in it but that something changed, sent through Kitloom\WpSchema\Live\Broadcasts::send() — after the commit, and never at the cost of the write. A private channel is authorised with LiveChannels::authorize() where the broadcaster is resolved. Something a person's account shows sends Kitloom\Site\Account\AccountChanged::sendTo($broadcasts, [$userId]).

Without this module nothing is sent and every part is what it always was. Tests use Kitloom\WpSchema\Testing\CollectsBroadcasts.

Read more ​

kitloom — sites on Laravel, built for you and run with AI.
Contact · Services · License · Refunds · Privacy · Community · YouTube · [email protected]