textalk/websocket
Archived, unmaintained WebSocket client and rudimentary single-connection server for PHP. Provides low-level read/write over WebSocket streams with handshake, close, and ping/pong support. No listeners, threading, or request association.
Pros:
Cons:
stream_context_create() setup (e.g., for wss://).pusher in config/broadcasting.php).WebSocket\Server → event(new MessageReceived($data))).ShouldQueue job.Upgrade: websocket headers).WebSocketChannel in Laravel’s broadcasting stack.High:
TimeoutException)./health endpoints or graceful shutdowns.Mitigation Strategies:
WebSocketManager with connection pooling).react/websocket + react/http for HTTP → WebSocket upgrades).sirn-se/websocket-php if it gains traction./vendor) to avoid Composer updates?stream_context_create()?| Laravel Component | Integration Strategy | Tools/Dependencies |
|---|---|---|
| Client | Replace HTTP polling with WebSocket\Client in: |
textalk/websocket, Guzzle, Laravel Queues |
| - Jobs/Queues | Async WebSocket polling (e.g., stock tickers, IoT telemetry). | Laravel Horizon, Redis |
| - Livewire/Alpine | Custom WebSocket events (e.g., real-time notifications). | Livewire, Alpine.js |
| - Artisan Commands | CLI-based WebSocket clients (e.g., php artisan websocket:fetch-data). |
Symfony Process, Laravel Console |
| Server | Deploy as a standalone service or Laravel micro-service. | Nginx, Docker, Laravel Forge |
| - Artisan Command | Single-threaded server: php artisan websocket:serve. |
PHP-FPM, Supervisor |
| - Lumen Micro-service | Lightweight WebSocket server (e.g., lumen-websocket). |
Lumen, Pound (reverse proxy) |
| - ReactPHP/Swoole | Scale to high concurrency (e.g., react/websocket + react/http). |
ReactPHP, Swoole |
| Database | Use Redis for: | Redis, Predis |
| - Pub/Sub Backend | Fan out WebSocket messages to multiple Laravel instances. | Laravel Broadcasting |
| - Connection Registry | Track active WebSocket connections (e.g., redis:SADD active_connections:{user_id}). |
Laravel Cache |
| Logging | Inject PSR-3 logger (Monolog) via $server->setLogger(). |
Monolog, Laravel Log |
| Authentication | Custom middleware to validate WebSocket connections (e.g., JWT/Sanctum). | Laravel Sanctum, Tymon/JWT |
| TLS/HTTPS | Terminate TLS at Nginx and forward to Laravel’s PHP-FPM, or use stream_context_create() for wss://. |
Nginx, stream_context_create() |
composer require textalk/websocket.use WebSocket\Client;
class FetchStockData implements ShouldQueue
How can I help you explore Laravel packages today?