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

Connection Manager Extra Laravel Package

clue/connection-manager-extra

Extra connector decorators for ReactPHP Socket. Wrap ConnectorInterface to add retries, timeouts, delays, rejection rules, swapping, consecutive/random selection, concurrency limits and selective routing—without changing your async connect() code.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Async TCP/IP Decorators: The package extends ReactPHP’s Socket component, providing non-blocking, promise-based connection management—ideal for Laravel applications requiring high concurrency (e.g., real-time APIs, WebSockets, or async task queues).
  • Decorator Pattern: Each decorator (Repeat, Timeout, Delay, etc.) wraps a ConnectorInterface, enabling modular, composable connection logic without tight coupling. This aligns with Laravel’s service container and dependency injection principles.
  • Laravel Integration Points:
    • HTTP Clients: Can augment Laravel’s HttpClient (via reactphp/http-client) for async requests.
    • Queues: Useful for retryable async jobs (e.g., failed database connections).
    • WebSockets: Complements packages like beberlei/ratchet or react/websocket for async WebSocket servers/clients.
    • Event-Driven Workflows: Syncs with Laravel’s event loop (via react/event-loop) for async task pipelines.

Integration Feasibility

  • ReactPHP Ecosystem: Requires ReactPHP (react/socket, react/promise) as a dependency, which may introduce minor friction if the Laravel app isn’t already async-first.
  • Promise-Based API: Laravel’s native Promise support (via Illuminate\Support\Facades\Promise) is incompatible with ReactPHP’s PromiseInterface. A bridge (e.g., react/promise + Laravel’s Promise) would be needed.
  • Stream Abstraction: Works with PHP streams, so integration with Laravel’s StreamedResponse or Storage (e.g., S3 streams) is plausible but requires manual stream handling.
  • Middleware Compatibility: Decorators like Selective or Consecutive could mirror Laravel’s HTTP middleware, but would need custom middleware wrappers for HTTP routes.

Technical Risk

  • Async vs. Sync Laravel: Laravel’s core is synchronous; mixing async decorators with sync routes/jobs risks race conditions or unhandled promises. Mitigation: Restrict usage to queues, commands, or event listeners.
  • Error Handling: ReactPHP’s exceptions (e.g., ConnectionException) differ from Laravel’s HttpException/Throwable. A custom exception mapper may be needed for consistency.
  • Performance Overhead: Decorators add indirection; benchmarking is critical for high-throughput use cases (e.g., 10K+ concurrent connections).
  • Dependency Bloat: Adding ReactPHP (~50MB) may be overkill for simple Laravel apps. Tree-shaking (via Composer) can reduce impact.
  • PHP Version Support: While the package supports PHP 5.3–8.5, Laravel’s LTS (8.0+) is recommended for stability.

Key Questions

  1. Use Case Clarity:
    • Is this for async HTTP clients, WebSockets, retryable jobs, or network ACLs?
    • Example: "Will we use ConnectionManagerRepeat for failed database connections in a queue worker?"
  2. Async Adoption:
    • Is the team comfortable with promise-based async code? Training may be needed.
    • Will we use Laravel’s Promise facade or ReactPHP’s promises directly?
  3. Error Recovery:
    • How will async failures (e.g., ConnectionTimeout) map to Laravel’s error handling (e.g., App\Exceptions\Handler)?
  4. Scaling:
    • Will this run in Laravel Horizon (for queues) or a custom ReactPHP event loop?
    • How will we handle connection pooling (e.g., ConnectionManagerRepeat vs. Laravel’s retry() helper)?
  5. Testing:
    • How will we mock async decorators in PHPUnit? (Hint: Use React\Promise\Test\TestLoop.)

Integration Approach

Stack Fit

Laravel Component Integration Strategy Tools/Libraries
HTTP Client Wrap HttpClient with ConnectionManagerTimeout/Repeat for async retries. reactphp/http-client, Guzzle bridge
Queues Use decorators in queue workers (e.g., ConnectionManagerRepeat for DB retries). Laravel Queues + react/event-loop
WebSockets Replace sync WebSocket clients with ConnectionManagerDelay/Consecutive for failover. beberlei/ratchet, react/websocket
Event Loop Run ReactPHP’s loop alongside Laravel’s Swoole/Pcntl (if used) or as a separate process. react/event-loop, swoole
Middleware Create custom middleware to apply ConnectionManagerSelective to HTTP routes. Laravel Middleware + react/socket
Artisan Commands Use decorators in long-running commands (e.g., ConnectionManagerTimeout for APIs). Laravel Console + React\AsyncProcess

Migration Path

  1. Phase 1: Proof of Concept
    • Add clue/connection-manager-extra and react/socket to composer.json.
    • Implement a single decorator (e.g., ConnectionManagerRepeat) in a queue job or HTTP client.
    • Test with mocked async failures (e.g., ConnectionManagerReject).
  2. Phase 2: Core Integration
    • Build a Promise bridge between ReactPHP and Laravel (e.g., convert React\Promise to Illuminate\Support\Promise).
    • Integrate with Laravel’s HTTP client via a custom connector.
    • Example:
      $httpClient = new HttpClient();
      $retryConnector = new ConnectionManagerRepeat($httpClient->getConnector(), 3);
      $httpClient->setConnector($retryConnector);
      
  3. Phase 3: Full Adoption
    • Replace sync retries (e.g., retry() helper) with async decorators in critical paths.
    • Add monitoring for connection metrics (e.g., ConnectionManagerTimeout failures).
    • Document async best practices for the team.

Compatibility

  • Laravel 8/9/10: Fully compatible; use ReactPHP 1.0+ for stability.
  • Laravel 7: Possible but may require older ReactPHP versions (tested in changelog).
  • Swoole/Pcntl: ReactPHP’s loop can coexist with Laravel’s async drivers but requires careful event loop management.
  • Existing Async Packages: Conflicts unlikely, but avoid mixing ReactPHP and Amp in the same app.

Sequencing

  1. Start with Low-Risk Areas:
    • Queue Workers: Replace sync retries with ConnectionManagerRepeat.
    • API Clients: Add ConnectionManagerTimeout to external HTTP calls.
  2. Avoid Critical Paths Early:
    • Skip user-facing HTTP routes until async middleware is stable.
    • Avoid database connections (use Laravel’s built-in retry instead).
  3. Incremental Decorator Rollout:
    • Week 1: Timeout/Repeat for retries.
    • Week 2: Selective for network policies.
    • Week 3: Concurrent/Consecutive for failover.

Operational Impact

Maintenance

  • Dependency Updates:
    • ReactPHP and this package are actively maintained (last release: 2026-04-13).
    • SemVer compliance means minor updates are safe; major updates require testing.
  • Debugging:
    • Async stack traces are harder to debug than sync code. Use:
      • React\Debug\Debugger for async backtraces.
      • Structured logging (e.g., monolog with async handlers).
    • Example: Wrap decorators in a try-catch to log failures:
      $connector->connect('example.com')->then(
          fn($stream) => $stream->write('GET /'),
          fn($e) => Log::error('Connection failed', ['error' => $e->getMessage()])
      );
      
  • Monitoring:
    • Track connection metrics (success/failure rates, latency) via:
      • Laravel’s events + react/async listeners.
      • Prometheus exporter for ReactPHP (e.g., clue/prometheus).

Support

  • Team Skills:
    • Requires async PHP knowledge (promises, event loops). Provide:
      • Training on ReactPHP basics.
      • Cheat sheets for common patterns (e.g
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