Server SDK

Realtime WebSocket Notifications for Laravel

Trigger real-time WebSocket events from Laravel controllers, jobs, and queued tasks. Zero-dependency PHP SDK — no Guzzle, no Reverb, no Echo server to configure or maintain.

Server $ composer require apinator/apinator-php
Client $ npm install @apinator/client

Laravel's broadcast system is powerful but traditionally requires a separate WebSocket server — Laravel Reverb, Echo Server, or a Pusher subscription. Apinator gives you real-time WebSocket notifications from any Laravel controller, queued job, or listener with a simple API call. No additional server process, no Echo server to configure, and no infrastructure to manage.

Quick Start

How to add WebSocket notifications to Laravel

Add realtime features to your Laravel app in a few steps.

01

Install the PHP SDK

Add the server SDK via Composer. Zero dependencies — pure PHP 8.1+.

composer require apinator/apinator-php
02

Initialize in a service provider

Register the Apinator client as a singleton in your Laravel service container.

// app/Providers/AppServiceProvider.php use Apinator\Apinator; public function register(): void { $this->app->singleton(Apinator::class, fn () => new Apinator( appId: config('services.apinator.app_id'), key: config('services.apinator.key'), secret: config('services.apinator.secret'), cluster: config('services.apinator.cluster') ) ); }
03

Trigger WebSocket events from a controller

Publish real-time WebSocket events from any Laravel controller or queued job. All subscribed browser clients receive the notification instantly.

public function store(Request $request, Apinator $apinator) { $order = Order::create($request->validated()); $apinator->trigger( name: 'new-order', data: json_encode(['id' => $order->id]), channel: 'private-orders' ); }
04

Add a WebSocket channel auth route

Create a POST route that authenticates private WebSocket channel subscriptions using HMAC-SHA256 signing.

// routes/api.php Route::post('/realtime/auth', function (Request $request, Apinator $apinator) { $auth = $apinator->authenticateChannel( $request->input('socket_id'), $request->input('channel_name') ); return response()->json($auth); });

Why Laravel

Built for Laravel developers

Zero Dependencies

Pure PHP 8.1+ — no Guzzle, no cURL wrappers. Uses native stream context for HTTP requests.

Service Container Ready

Register as a singleton and inject via constructor. Follows Laravel dependency injection conventions.

Queue Compatible

Trigger events from Laravel queued jobs, listeners, and scheduled tasks. Works anywhere PHP runs.

Webhook Verification

Verify incoming webhook signatures in middleware or controller. Replay attack protection built in.

How WebSocket notifications work in a Laravel application

Laravel's traditional broadcasting system — Laravel Echo combined with a WebSocket server like Reverb or the older Laravel Echo Server — requires running a persistent WebSocket process alongside your web application. This adds operational complexity: a separate server to deploy, monitor for crashes, scale independently, and keep in sync with your Laravel authentication.

Apinator removes this complexity. Your Laravel application calls the Apinator SDK from a controller, job, or listener — a single method call that publishes a real-time WebSocket event to all subscribed browser clients. Apinator's infrastructure maintains the persistent WebSocket connections. Your Laravel server stays stateless and doesn't hold any WebSocket connections, which simplifies horizontal scaling behind a load balancer.

The PHP SDK has zero dependencies and uses PHP's native stream contexts for HTTP requests — no Guzzle version to pin, no Composer conflicts, and no compatibility issues across PHP 8.1+ versions. It works equally well in controllers, Queued Jobs, Artisan commands, scheduled tasks, and Laravel Listeners.

Full Example

Full Example: Realtime WebSocket Notifications in a Laravel Controller

Complete WebSocket example: Laravel service provider setup, controller for triggering real-time events, auth route for private channels, and a JavaScript frontend.

app/Http/Controllers/OrderController.php
namespace App\Http\Controllers; use App\Models\Order; use Illuminate\Http\Request; use Apinator\Apinator; class OrderController extends Controller { public function __construct( private readonly Apinator $apinator ) {} public function store(Request $request) { $order = Order::create($request->validated()); $this->apinator->trigger( name: 'new-order', data: json_encode([ 'id' => $order->id, 'total' => $order->total, ]), channel: 'private-orders' ); return response()->json($order, 201); } }

Start building realtime Laravel apps

Completely free. No credit card. No catch.