Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Websocket Laravel Package

phrity/websocket

PHP WebSocket client and multi-connection server with ws/wss support. Includes listener callbacks, standard Close and Ping/Pong handling, optional deflate compression, fragmentation and masking support, plus middleware system for extending behavior.

View on GitHub
Deep Wiki
Context7

[php-lib] WebSocket client and server in PHP

Frequently asked questions about Websocket
Can I use phrity/websocket to replace Laravel Echo/Pusher in my Laravel app?
Yes, this package can fully replace Laravel Echo or Pusher for custom WebSocket endpoints. It supports both client and server modes, allowing you to build real-time features like chat or notifications without third-party dependencies. Use it alongside Laravel’s event system for seamless integration.
How do I authenticate WebSocket connections in Laravel with Sanctum or JWT?
You can authenticate WebSocket connections by extending the middleware system. For Sanctum, validate tokens in a custom middleware attached to the server, then grant access to specific routes. For JWT, decode the token during the handshake and attach user data to the connection object.
Does phrity/websocket support Laravel’s logging system (Log facade) for debugging?
Yes, you can integrate Laravel’s Log facade by injecting it into your custom middleware or server callbacks. For example, log connection events or errors using `Log::debug()` or `Log::error()` for consistency with Laravel’s logging standards.
What’s the best way to monitor WebSocket connections in Laravel (e.g., Sentry or Prometheus)?
For Sentry, wrap WebSocket events (e.g., `onOpen`, `onClose`) in try-catch blocks and report exceptions. For Prometheus, expose metrics via middleware (e.g., track active connections, message counts) and use Laravel’s Prometheus client integration.
How do I handle WebSocket failures in production (e.g., fallback to SSE or polling)?
Implement a retry mechanism with exponential backoff in your client code. For fallbacks, detect WebSocket disconnections via `onClose` events and switch to Server-Sent Events (SSE) or polling using Laravel’s HTTP client or queue jobs.
Is phrity/websocket compatible with Laravel 10+ and PHP 8.5+?
Yes, the package is fully compatible with Laravel 10+ and PHP 8.5+. It leverages modern PHP features and PSR standards (PSR-7, PSR-17) that Laravel already supports. For older Laravel versions, you may need to pin dependencies or use polyfills.
How do I configure SSL/TLS for wss:// in Laravel?
SSL/TLS is configured via the server’s context settings. Use Laravel’s `config/websockets.php` or environment variables to specify the SSL certificate path and key. The package supports standard OpenSSL configurations, so ensure your server has valid certificates.
Can I use phrity/websocket with Laravel Horizon for scaling WebSocket connections?
While the package itself is thread-safe for multi-connections, scaling requires additional infrastructure. Use Laravel Horizon to manage WebSocket workers alongside queues, but note that WebSocket connections are stateful—consider load balancing with tools like Nginx or Envoy for high traffic.
What alternatives exist to phrity/websocket for Laravel WebSockets?
Alternatives include `beyondcode/laravel-websockets` (built on Ratchet), `reactphp/websocket` (Reactor-based), or `pusher/pusher-php-sdk` (official Pusher client). This package stands out for its middleware system, deflate compression, and direct Laravel integration without extra dependencies.
How do I create a custom Artisan command to start/stop the WebSocket server in Laravel?
Extend Laravel’s `Artisan::command()` to instantiate the WebSocket server and manage its lifecycle. For example, create `php artisan websocket:start` to launch the server with SSL and logging, then use Laravel’s process management (e.g., Supervisor) to keep it running in production.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky