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

Laravel Websocket Laravel Package

bugover/laravel-websocket

Fork of beyondcode/laravel-websockets bringing WebSockets to Laravel as a drop-in Pusher replacement. Supports SSL, Laravel Echo, and a debug dashboard, plus added connection events and two-way client-to-server messaging.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Real-Time Architecture Alignment: Perfectly integrates with Laravel’s event-driven architecture, enabling seamless real-time features (e.g., notifications, live collaboration) without third-party dependencies. Leverages Laravel Echo for client-side compatibility, reducing frontend refactoring.
  • Modularity: Supports custom channel managers (Redis, database), SSL/TLS, and multi-tenancy, making it adaptable to complex architectures. The apps configuration in websockets.php allows isolation of different WebSocket instances for microservices or multi-tenant apps.
  • Two-Way Communication: Extends beyond traditional pub/sub with bidirectional messaging (client ↔ server), enabling use cases like user presence, acknowledgments, or device telemetry without additional infrastructure.
  • Debugging Tools: Built-in dashboard and logging reduce operational friction during development and debugging, aligning with DevOps best practices for observability.

Integration Feasibility

  • Laravel Broadcasting: Drop-in replacement for Pusher with minimal configuration changes (update broadcasting.php and .env). Existing event publishing logic (event(new MyEvent())) remains unchanged.
  • Client-Side Compatibility: Full support for Laravel Echo and Pusher SDKs (JavaScript, Python, etc.) with config updates. No frontend refactoring required for SPAs using Echo.
  • Dependency Overhead: Lightweight core dependencies (pusher/pusher-php-server, reactphp) with optional extensions (ev, redis) for scaling. No heavy frameworks or databases required for basic functionality.
  • Database: Optional statistics tracking (useful for analytics) but not critical for core WebSocket functionality. Supports MySQL, PostgreSQL, and SQLite.

Technical Risk

  • Concurrency Limits:
    • Default stream_select event loop caps connections at 1,024. Mitigation: Use ev or event PECL extensions for 60K+ connections (requires PHP tuning).
    • Redis Channel Manager: Recommended for high-channel-count apps (>100K channels) to avoid memory issues with in-memory ArrayChannelManager.
  • State Management:
    • In-memory channel storage may not scale for apps with millions of channels. Redis integration required for horizontal scaling.
    • No built-in persistence for WebSocket messages (stateless by design). Use Laravel’s broadcasting queue (queue:work) for reliability.
  • SSL/TLS Complexity:
    • Requires manual certificate setup (.local_cert, .local_pk) for production. Reverse proxy (Nginx) recommended for TLS termination.
    • Self-signed certs may trigger browser warnings; use Let’s Encrypt for production.
  • Fork Risks:
    • Active development (last release: 2025-06-14) but forked from beyondcode/laravel-websockets. Monitor for breaking changes or security updates.
    • No official enterprise support; rely on community/GitHub issues for troubleshooting.

Key Questions

  1. Scalability Requirements:
    • What is the expected peak concurrent connections? If >1K, evaluate ev/event extensions or Redis channel manager.
    • What is the channel count per app? If >100K, confirm Redis integration plan.
  2. Deployment Constraints:
    • Can the WebSocket server run on the same host as Laravel, or does it require a dedicated instance?
    • Are there restrictions on file descriptors (ulimit -n) or PECL extensions?
  3. Security and Compliance:
    • Is SSL/TLS mandatory? If yes, ensure certificates are available and configure reverse proxy.
    • Are there multi-tenancy requirements? If yes, validate apps configuration and isolation.
  4. Operational Overhead:
    • Is real-time monitoring required? Enable enable_statistics and configure database retention.
    • What is the fallback strategy for outages? Use Laravel’s fallback broadcasting driver or hybrid Pusher + self-hosted setup.
  5. Team Expertise:
    • Does the team have experience with PHP event loops (ev, reactphp) or Redis tuning?
    • Is there Unix sysadmin support for ulimit, process management, and SSL setup?

Integration Approach

Stack Fit

  • Laravel Compatibility:
    • Versions: Supports Laravel 7–11 (check composer.json for exact ranges). Tested with PHP 7.4+.
    • Broadcasting: Replaces pusher driver in config/broadcasting.php with local host/port. No changes to event publishing logic.
  • PHP Extensions:
    • Required: openssl, pcntl, pthreads (for multi-process scaling).
    • Recommended: ev/event PECL for high-concurrency setups (>1K connections).
    • Optional: redis for channel management or pdo_mysql/pdo_pgsql for statistics.
  • Frontend:
    • Laravel Echo: Zero-config if using broadcaster: 'pusher'. Auto-detects local WebSocket server.
    • Pusher SDKs: Update config to target self-hosted endpoint (e.g., ws://your-domain:6001).
    • Raw WebSocket Clients: Connect to ws://your-domain:6001/apps/{app_id}.
  • Database:
    • Optional for statistics. Supports MySQL, PostgreSQL, SQLite. Default retention: 60 days.

Migration Path

  1. Installation:
    composer require bugover/laravel-websocket
    php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="config"
    php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="migrations"
    php artisan migrate  # Optional: For statistics
    
  2. Configuration:
    • Update config/broadcasting.php:
      'pusher' => [
          'driver' => 'pusher',
          'key' => env('PUSHER_APP_KEY'),
          'secret' => env('PUSHER_APP_SECRET'),
          'app_id' => env('PUSHER_APP_ID'),
          'options' => [
              'host' => env('PUSHER_HOST', '127.0.0.1'),
              'port' => env('PUSHER_PORT', 6001),
              'scheme' => env('PUSHER_SCHEME', 'http'),
              'encrypted' => true,
              'useTLS' => env('PUSHER_SCHEME') === 'https',
          ],
      ],
      
    • Update .env:
      PUSHER_APP_ID=your_app_id
      PUSHER_APP_KEY=your_app_key
      PUSHER_APP_SECRET=your_app_secret
      PUSHER_HOST=127.0.0.1
      PUSHER_PORT=6001
      PUSHER_SCHEME=http
      
  3. Client-Side:
    • Laravel Echo: No changes needed. Use:
      window.Echo = new Echo({
          broadcaster: 'pusher',
          key: process.env.MIX_PUSHER_APP_KEY,
          wsHost: window.location.hostname,
          wsPort: 6001,
          forceTLS: false,
          disableStats: true,
      });
      
    • Pusher SDKs: Update to point to self-hosted server:
      const pusher = new Pusher('your_app_key', {
          wsHost: 'your-domain',
          wsPort: 6001,
          forceTLS: false,
          disabledStats: true,
      });
      
  4. Testing:
    • Start server:
      php artisan websockets:serve
      
    • Verify with:
      curl -N http://localhost:6001/apps/{app_id}/channels/private-test-channel
      
    • Check debug dashboard at /laravel-websockets.

Compatibility

  • Laravel Echo: Full compatibility. Uses Pusher’s API under the hood; no client-side changes required.
  • Pusher SDKs: Require config updates to target self-hosted endpoint. Test all SDKs (JavaScript, Python, etc.) post-migration.
  • Third-Party Packages: Audit for hardcoded Pusher endpoints (e.g., pusher.com). Replace with local host/port.
  • Legacy Code: Minimal risk if using Laravel’s broadcasting facade. Avoid hardcoded Pusher URLs in business logic.
  • Redis: If using Redis channel manager, ensure predis/predis is installed and REDIS_HOST is configured in websockets.php.

Sequencing

  1. Development:
    • Local Testing: Run php artisan websockets:serve alongside Laravel’s dev server.
    • Debug Dashboard: Use /laravel-websockets to monitor connections/events.
    • Unit Tests: Mock WebSocket events in Laravel tests (e.g., using Mockery).
  2. Staging:
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
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