Go to file
Fabian @ Blax Software e45d8dff20 F websockets:watch -v — per-connection rows (socket id, user, duration)
Verbose mode reuses Symfony's built-in -v flag (the short option is
reserved, so a custom one can't be added). Each channel summary is
followed by sub-rows showing the socket id, the authed user (falling
back to "Guest" or the user id if the user blob expired), and how long
the connection has been open.

Connection start times are written by Handler::establishConnection() into
ws_connection_<slug(socketId)> on open and forgotten on close. Also
fixed a latent bug in finalizeConnectionClose() where the forget key was
missing the slug() call that the reader has always used — previously
invisible because nothing wrote the key, now load-bearing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:42:26 +02:00
.github docs: add copilot instructions 2026-04-16 08:27:28 +02:00
config fix: harden IPC callbacks and decouple auth lookup via configurable resolver 2026-04-17 11:03:02 +02:00
database/migrations Renovation 2025-01-16 08:54:02 +01:00
docs A tests, documentation for helpers and lifecycle 2026-04-02 12:44:16 +02:00
resources/views Merge 2.x changes (#1043) 2022-10-06 13:46:54 +02:00
routes A default broadcasting route, I ip on close 2025-12-05 19:56:44 +01:00
src F websockets:watch -v — per-connection rows (socket id, user, duration) 2026-04-27 13:42:26 +02:00
tests I open presence channel test 2026-04-21 16:52:44 +02:00
.codecov.yml Addded .codecov.yml 2020-08-23 13:54:22 +03:00
.editorconfig wip 2020-09-10 22:59:26 +03:00
.gitattributes Update .gitattributes 2020-06-02 11:26:55 +02:00
.gitignore wip 2020-09-10 22:59:26 +03:00
.scrutinizer.yml wip 2020-09-10 22:59:26 +03:00
.styleci.yml wip 2020-09-10 22:59:26 +03:00
CONTRIBUTING.md initial commit 2018-11-20 09:54:06 +01:00
LICENSE wip 2020-09-10 22:59:26 +03:00
README.md A tests, documentation for helpers and lifecycle 2026-04-02 12:44:16 +02:00
composer.json IA helpers 2026-02-03 15:03:50 +01:00
phpunit.xml I performance, A testing & event-driven 2026-01-24 13:34:29 +01:00

README.md

Laravel WebSockets

[!NOTE] This package is actively maintained as a fork of beyondcode/laravel-websockets.

Plug-and-play WebSockets for Laravel with a Pusher-compatible protocol, a fast fork-based handler, and practical helpers for broadcasting and testing.

Why this package

  • Drop-in broadcasting backend for Laravel apps that already use Echo/Pusher-compatible clients
  • Fast local handler with async processing via pcntl_fork
  • Protocol compatibility for both modern websocket.* and legacy pusher:* action formats
  • Built-in developer ergonomics: helper functions, service methods, and rich test helpers

Install in 2 minutes

  1. Install package
composer require blax-software/laravel-websockets
  1. Publish config
php artisan vendor:publish --provider="BlaxSoftware\\LaravelWebSockets\\WebSocketsServiceProvider" --tag="config"
  1. Start server
php artisan websockets:serve

Default server URL is ws://127.0.0.1:6001.

Helper functions (broadcast from anywhere)

The package ships with global helpers in src/helpers_global.php.

// Broadcast to everyone on a channel
ws_broadcast('chat.message', ['text' => 'Hello'], 'chat');

// Whisper to specific socket IDs only
ws_whisper('chat.typing', ['typing' => true], ['1234.1', '1234.2'], 'chat');

// Broadcast to everyone except listed sockets
ws_broadcast_except('chat.message', ['text' => 'Server msg'], ['1234.1'], 'chat');

// Check if local unix-socket broadcaster is available
if (ws_available()) {
	ws_broadcast('app.health', ['ok' => true]);
}

// Build protocol auth payload for private/presence channels
$auth = wsSession('private-updates', ['user_id' => 7, 'user_info' => ['name' => 'Jane']]);

Service API

Use the service directly when you prefer explicit class calls over helpers.

use BlaxSoftware\LaravelWebSockets\Services\WebsocketService;

WebsocketService::send('metrics.tick', ['count' => 1], 'websocket');
WebsocketService::whisper('chat.typing', ['typing' => true], ['1234.1'], 'chat');
WebsocketService::broadcastExcept('chat.message', ['text' => 'Hi'], ['1234.1'], 'chat');

// Optional in-process tracking helpers
WebsocketService::setUserAuthed($socketId, $userId);
$authed = WebsocketService::getAuthedUsers();

Testing experience

The test suite includes helper-first patterns so WebSocket tests stay short and readable.

Test helpers

  • newConnection()
  • newActiveConnection(['channel'])
  • newPrivateConnection('private-channel')
  • newPresenceConnection('presence-channel', ['user_id' => 1, 'user_info' => [...]])

Example

$connection = $this->newActiveConnection(['chat']);

$this->wsHandler->onMessage($connection, new Message([
	'event' => 'websocket.ping',
	'data' => new stdClass(),
]));

$connection->assertSentEvent('websocket.pong');

Run tests:

vendor/bin/phpunit --exclude-group=stability,stress,integration,requires-server

Documentation

Changelog

See CHANGELOG.

Security

Please report vulnerabilities via issue tracker or by email: office@blax.at.

Credits

License

MIT. See LICENSE.md.