Go to file
Blax Software 96b3de6a53 feat: initial reactphp-kernel — shared ReactPHP backbone
Protocol-agnostic backbone extracted from blax-software/laravel-websockets so
WebSockets, WebRTC signaling and future protocols attach to one long-lived
process + loop + IPC + supervision:

- Kernel: loop lifecycle, server registration, signals, graceful stop
- Contracts\Server: attachable protocol server (boot/shutdown)
- Server\SocketServerFactory: plain/TLS listening socket (no framework coupling)
- Ipc\SocketPairIpc: event-driven parent/child IPC (lifted verbatim)
- Process\SignalHandler + ChildReaper (reusable form of laravel-websockets #982)

rel learn-atc #1055 #1051

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 13:07:47 +02:00
src feat: initial reactphp-kernel — shared ReactPHP backbone 2026-07-07 13:07:47 +02:00
.gitignore feat: initial reactphp-kernel — shared ReactPHP backbone 2026-07-07 13:07:47 +02:00
LICENSE feat: initial reactphp-kernel — shared ReactPHP backbone 2026-07-07 13:07:47 +02:00
README.md feat: initial reactphp-kernel — shared ReactPHP backbone 2026-07-07 13:07:47 +02:00
composer.json feat: initial reactphp-kernel — shared ReactPHP backbone 2026-07-07 13:07:47 +02:00

README.md

blax-software/reactphp-kernel

A small, protocol-agnostic ReactPHP backbone: one long-lived process, one event loop, one IPC primitive, and one signal/graceful-shutdown story that many protocol servers attach to.

It is the shared foundation extracted from blax-software/laravel-websockets so that WebSockets, WebRTC signaling/media (blax-software/laravel-webrtc), and future protocols (SIP, ...) do not each re-implement the plumbing.

blax-software/reactphp-kernel        <- this package (the backbone)
   ├─ laravel-websockets             <- WS on the kernel
   └─ laravel-webrtc                 <- WebRTC signaling on the kernel
         └─ Rust/str0m media core    <- via ext-php-rs

What's in the box

Piece Responsibility
Kernel Owns the loop; registers Servers; installs signals; run() / graceful stop().
Contracts\Server An attachable protocol server: boot(LoopInterface) (non-blocking) + shutdown().
Server\SocketServerFactory Plain-TCP or TLS listening socket (no framework coupling).
Ipc\SocketPairIpc Event-driven parent/child IPC over a Unix socket pair (no polling).
Process\SignalHandler SIGINT/SIGTERM → graceful shutdown (no-op without ext-pcntl).
Process\ChildReaper Reaps exited forked children (SIGCHLD + periodic backstop) — the reusable form of laravel-websockets #982.

Usage

use BlaxSoftware\ReactPhpKernel\Kernel;

(new Kernel())
    ->reapChildren()                 // optional: auto-reap forked children
    ->register($webSocketServer)     // any Contracts\Server
    ->register($webRtcSignaling)
    ->onBoot(fn (Kernel $k) => /* warm caches, announce ready, ... */ null)
    ->run();                         // boots servers, installs signals, runs the loop (blocks)

Implement Contracts\Server to plug in a protocol:

use BlaxSoftware\ReactPhpKernel\Contracts\Server;
use BlaxSoftware\ReactPhpKernel\Server\SocketServerFactory;
use React\EventLoop\LoopInterface;

final class MyServer implements Server
{
    private $socket = null;

    public function name(): string { return 'my-server'; }

    public function boot(LoopInterface $loop): void
    {
        $this->socket = SocketServerFactory::create('0.0.0.0:9000', $loop);
        $this->socket->on('connection', function ($conn) { /* ... */ });
    }

    public function shutdown(): void
    {
        $this->socket?->close();
    }
}

Requirements

  • PHP >= 8.1
  • react/event-loop, react/socket, react/stream
  • ext-pcntl (suggested) for signal handling + child reaping
  • ext-sockets (suggested) for SocketPairIpc

License

MIT © Blax Software