<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Dimath Jayasinghe]]></title><description><![CDATA[Writing about my developer journey and the projects I build. The current one is wsrv, a from-scratch C++ WebSocket server for PHP and Laravel: github.com/Dimath]]></description><link>https://dimathjayasinghe.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6b0af0e2dbc8c701e14ac1a7/d64a6996-a99e-46bd-ba52-166209950495.png</url><title>Dimath Jayasinghe</title><link>https://dimathjayasinghe.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Mon, 30 Nov 2026 23:44:15 GMT</lastBuildDate><atom:link href="https://dimathjayasinghe.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[wsrv 1.1: Laravel Echo on a C++ WebSocket daemon]]></title><description><![CDATA[wsrv is a C++ WebSocket server for PHP. Version 1.1 adds Laravel Echo support: what was checked, what was not, and what went wrong.]]></description><link>https://dimathjayasinghe.hashnode.dev/wsrv-1-1</link><guid isPermaLink="true">https://dimathjayasinghe.hashnode.dev/wsrv-1-1</guid><category><![CDATA[PHP]]></category><category><![CDATA[Laravel]]></category><category><![CDATA[websockets]]></category><dc:creator><![CDATA[Dimath Jayasinghe]]></dc:creator><pubDate>Sat, 28 Nov 2026 16:05:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0af0e2dbc8c701e14ac1a7/f7d8343e-c93e-42e6-91be-4496c5c2e7ad.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>A WebSocket server that your PHP application talks to over a socket, now with Laravel Echo support, and an honest list of what was checked and what was not.</em></p>
<h2>What wsrv is</h2>
<p>PHP's usual process-per-request model is a poor fit for holding thousands of open sockets. wsrv puts the sockets somewhere else. <code>wsrvd</code> is a daemon written in C++23, a from-scratch implementation of RFC 6455 with no third-party WebSocket library, under the Apache-2.0 license. It owns the browser connections. Your PHP code connects to it over a Unix socket (or, since 1.1, over TCP with a generated token) and only reacts to events: a browser asked to connect, a message arrived, a connection closed.</p>
<pre><code class="language-sh">docker run -d --name wsrvd -p 8080:8080 \
  -v wsrv-ipc:/run/wsrv \
  -e WSRVD_ALLOW_ORIGIN=https://app.example.com \
  -e WSRVD_BROKER=true \
  dimathjayasinghe/wsrvd:1.1.0
</code></pre>
<pre><code class="language-php">$worker = new Wsrv\Worker(Wsrv\Client::connect('/run/wsrv/ipc.sock'));
$worker-&gt;on('message', fn ($conn, $data) =&gt; $conn-&gt;send($data));
$worker-&gt;run();
</code></pre>
<h2>What 1.1 adds: Laravel Echo</h2>
<p>Version 1.1.0, released on 28 November 2026, lets a Laravel application use <code>broadcast()</code> and Laravel Echo with wsrv as the WebSocket server.</p>
<pre><code class="language-sh">composer require wsrv/client
</code></pre>
<p>Run the daemon with a publish token that its own generator made (since 1.1 the daemon accepts no other), and with limits sized for a channel per user. These commands are the ones in the guide; the numbers on the last two lines suit a site with up to about 10,000 browsers online, and the guide explains each one:</p>
<pre><code class="language-sh">wsrvd --generate-token=/run/wsrv/publish.token
wsrvd --ipc-socket=/run/wsrv/ipc.sock --listen-port=8080 \
      --allow-origin=https://app.example.com \
      --broker=true --publish-port=9200 --publish-token-file=/run/wsrv/publish.token \
      --max-message-size=262144 --ipc-max-frame=524286 \
      --broker-max-topics=50000 --broker-max-subscriptions=500000
</code></pre>
<p>Then the Laravel side:</p>
<pre><code class="language-plaintext">BROADCAST_CONNECTION=wsrv
WSRV_APP_KEY=any-public-name
WSRV_APP_SECRET=at-least-16-random-bytes-never-in-the-browser
WSRV_PUBLISH_TOKEN_FILE=/run/wsrv/publish.token
</code></pre>
<pre><code class="language-sh">php artisan wsrv:echo
</code></pre>
<p><code>wsrv:echo</code> is a small worker that speaks the Pusher WebSocket protocol to the browser and checks the signatures your <code>/broadcasting/auth</code> route hands out. In the browser you use Echo's usual options (<code>key</code>, <code>wsHost</code>, <code>wsPort</code>, <code>forceTLS</code>) and the usual calls: <code>Echo.channel(...)</code>, <code>Echo.private(...)</code>, <code>Echo.join(...)</code>, whispers included. Public, private, presence and encrypted channels are implemented and tested.</p>
<p>The full guide, including the Docker, systemd and Sail setups and the limits, is <a href="https://github.com/DimathJayasinghe/wsrv/blob/main/docs/LARAVEL_ECHO.md">docs/LARAVEL_ECHO.md</a>.</p>
<h2>What was actually run</h2>
<p>On 28 November 2026 the real <code>pusher-js</code> 8.6.0 and <code>laravel-echo</code> 2.6.3 ran in Chrome 156 against wsrv twice: once with a small stand-in for the Laravel routes and once with a real Laravel 13.43 application. Both runs passed 12 of 12 checks.</p>
<p>Two things that run did <em>not</em> cover. Laravel 13.43 is the only Laravel version it ran against, and Echo was configured with its <code>reverb</code> broadcaster option; the <code>pusher</code> broadcaster reaches the same <code>pusher-js</code> code but was not run.</p>
<h2>Claims you can check</h2>
<p>A claim you cannot check is an adjective, so the repository has a page, <a href="https://github.com/DimathJayasinghe/wsrv/blob/main/docs/EVIDENCE.md">docs/EVIDENCE.md</a>, that lists each claim, the command that checks it, the last result and what that result does not show. A few rows:</p>
<ul>
<li><strong>Protocol.</strong> Autobahn|Testsuite: 517 cases, 0 failed, plain and over <code>wss://</code>, run on the 1.0.0 sources on 26 November 2026. Not re-run for 1.1.</li>
<li><strong>Tests.</strong> 1,634 tests pass with AddressSanitizer and UBSan, and the same suite runs under ThreadSanitizer in CI. 14 fuzz targets run for five seconds each on every change, which is a smoke test, not continuous fuzzing.</li>
<li><strong>Staying up.</strong> A two-hour run on the release image with 200 reconnecting clients and 162 injected faults (daemon restarts, <code>kill -9</code>, network cuts): every client was back after every fault and the daemon never crashed. Run by hand on 25 November 2026, on the 1.0 line.</li>
<li><strong>Releases.</strong> Images are scanned before they are pushed, signed with cosign and carry build provenance; each release has an SBOM and checksums. For <code>v1.1.0</code> they were checked from the published artifacts after release (checksums, attestations, the cosign signature on GHCR and on Docker Hub, and that both registries carry the same image); the record is in section 7 of <a href="https://github.com/DimathJayasinghe/wsrv/blob/main/docs/RELEASE.md">docs/RELEASE.md</a>.</li>
</ul>
<p><strong>There has been no external security audit</strong> of the code, the protocol implementation or the TLS configuration. The reviews done during development are recorded in the repository with their findings.</p>
<h2>What went wrong on the way</h2>
<p>A project that lists its evidence should also list its mistakes. Here is some of what the checking found.</p>
<p><strong>A benchmark found bugs no unit test had reached.</strong> Running thousands of connections showed that the server accepted at most 4,095 at once (its event queue held 4,096 slots), that a broadcast to a 5,000-subscriber room reached only 61 percent of it, and that closing 5,000 connections left 904 open for good. All three are fixed; the write-ups are in <a href="https://github.com/DimathJayasinghe/wsrv/blob/main/docs/BENCHMARKS.md">BENCHMARKS.md</a> and the lessons in <code>docs/learning/</code>.</p>
<p><strong>A security review of the Echo branch found a way to lock everyone else out.</strong> On the default configuration, 16 scripted connections from one address joined 1,023 anonymous public channel names in 0.07 seconds, and a signed-in user who arrived afterwards was refused <code>private-user.7</code> and <code>presence-room.1</code> with <code>LimitReached: The server is at its channel limit</code>. It needed no signature and broke none of the per-connection limits. Public channel names now have their own budget (<code>maxPublicChannels</code>, default 512) and a site can list its public channels exactly. The change landed before the release.</p>
<p><strong>A message that could never be sent used to vanish.</strong> A message larger than the outbound queue could take was accepted and then silently dropped. It is now refused where the sender can see it.</p>
<p><strong>One breaking change, on purpose.</strong> In 1.1 the publish token must be one that <code>wsrvd --generate-token</code> made. A hand-made token (for example from <code>openssl rand</code>) now stops the start with a message that says how to fix it. Upgrading from 1.0 starts at <a href="https://github.com/DimathJayasinghe/wsrv/blob/main/docs/UPGRADING.md">docs/UPGRADING.md</a>.</p>
<h2>Speed, with both sides</h2>
<p><a href="https://github.com/DimathJayasinghe/wsrv/blob/main/docs/BENCHMARKS.md">docs/BENCHMARKS.md</a> compares wsrv with the PHP WebSocket servers people commonly run, with every number, the noise between runs and the harness, so that you can rerun it. On one laptop under Docker Desktop:</p>
<ul>
<li>With <strong>four CPUs</strong>, wsrv does 1.5 to 1.8 times the echo messages per second of the single-process servers at 64 connections, and a broadcast reaches the last of 5,000 subscribers in about half the time.</li>
<li>Pinned to <strong>one CPU</strong>, wsrv is <strong>behind</strong> on echo by about 10 to 25 percent, because the daemon and the PHP worker are two processes and every message crosses a Unix socket twice.</li>
</ul>
<p>The benchmark did not measure TLS, permessage-deflate, authentication, a database behind your handlers or a WAN, and the load generator was written by this project. It is a comparison, not a capacity plan.</p>
<h2>Limits to know before you rely on it</h2>
<ul>
<li>One daemon and one worker per application. There is no backplane between daemons.</li>
<li>Delivery is at most once. There is no replay of what was published while a client was disconnected.</li>
<li>Linux only, with <code>amd64</code> and <code>arm64</code> images.</li>
<li>1.1 is a new minor release of a project that is a few weeks old (first commit 24 October 2026). Pin an exact version.</li>
</ul>
<h2>Try it, and tell me what breaks</h2>
<ul>
<li>Code and issues: <a href="https://github.com/DimathJayasinghe/wsrv">https://github.com/DimathJayasinghe/wsrv</a></li>
<li>Image: <code>dimathjayasinghe/wsrvd</code> on Docker Hub (also <code>ghcr.io/dimathjayasinghe/wsrvd</code>), which you can verify with <code>cosign verify</code>, as the Docker Hub page describes.</li>
<li>PHP package: <code>wsrv/client</code> on Packagist.</li>
<li>Laravel Echo guide: <a href="https://github.com/DimathJayasinghe/wsrv/blob/main/docs/LARAVEL_ECHO.md">docs/LARAVEL_ECHO.md</a></li>
</ul>
<p>The most useful reports are the ones that break a claim on this page: an Echo feature that does not behave like the Pusher protocol says, a Laravel version other than 13.43, a number that does not reproduce on your hardware. Open an issue, or reply here.</p>
]]></content:encoded></item></channel></rss>