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 promise-based decorators for async TCP/IP connections. This aligns well with Laravel applications leveraging ReactPHP (e.g., via spatie/react or reactphp/react) for non-blocking I/O, particularly in:
    • High-concurrency services (e.g., real-time APIs, WebSockets, or async task queues).
    • Microservices requiring fine-grained connection control (e.g., retries, timeouts, or selective routing).
    • Legacy system integration where blocking fsockopen()/stream_socket_client() is replaced with async alternatives.
  • Laravel Compatibility: Laravel’s core is synchronous, but extensions like Laravel Horizon, Laravel Echo, or custom async workers (e.g., via spatie/react) can integrate this package. For synchronous Laravel apps, this would require wrapping decorators in Promises (e.g., React\Promise) or using Laravel’s Bus with async dispatchers.

Integration Feasibility

  • ReactPHP Dependency: The package requires ReactPHP (specifically react/socket). Laravel apps without ReactPHP would need to:
    • Add reactphp/socket and reactphp/promise to composer.json.
    • Initialize a ReactPHP event loop (e.g., React\EventLoop\Factory::create()) and integrate it with Laravel’s lifecycle (e.g., via service providers or console commands).
  • Promise-Based API: Laravel’s native Promise facade (Guzzle-based) is incompatible. The package uses ReactPHP’s Promise, requiring:
    • Adapters (e.g., react/promise-timer for timeouts) or custom wrappers to bridge ReactPHP Promises with Laravel’s ecosystem.
    • Careful handling of async/await patterns in Laravel (e.g., using await in async contexts like queues or jobs).

Technical Risk

  • Blocking vs. Non-Blocking: Laravel’s synchronous core may struggle with:
    • Long-running async operations (e.g., timeouts/retry logic) blocking HTTP requests.
    • State management (e.g., connection pools or event loops) conflicting with Laravel’s request lifecycle.
  • Error Handling: ReactPHP’s exceptions (e.g., ConnectionException) must be mapped to Laravel’s exception handlers or middleware.
  • Testing Complexity: Async decorators require mocking ReactPHP components (e.g., ConnectorInterface) and testing promise chains, which may complicate Laravel’s PHPUnit setup.
  • Performance Overhead: Decorators add layers to connection logic. Benchmarking is critical for latency-sensitive apps (e.g., real-time systems).

Key Questions

  1. Use Case Justification:
    • Why async connections? Is this for real-time features, background jobs, or legacy system integration?
    • Could synchronous alternatives (e.g., Laravel’s HttpClient with retries) suffice?
  2. Integration Strategy:
    • Will this replace existing connection logic (e.g., Guzzle, cURL) or augment it?
    • How will the ReactPHP event loop be managed (e.g., per-request, global, or in workers)?
  3. Error Recovery:
    • How will connection failures (e.g., retries exhausted) be surfaced to Laravel’s error handlers?
    • Are there circuit breaker patterns needed beyond the package’s retries?
  4. Scaling:
    • Will connections be pooled (e.g., ConnectionManagerPool) or managed per-request?
    • How will this interact with Laravel’s queue workers or Horizon?
  5. Maintenance:
    • Who will manage the ReactPHP event loop and its lifecycle?
    • Are there monitoring needs for connection metrics (e.g., retry rates, timeouts)?

Integration Approach

Stack Fit

  • Core Requirements:
    • ReactPHP: Required for async I/O. Laravel apps must integrate reactphp/socket and reactphp/promise.
    • Promise Handling: Laravel’s native Promise facade is incompatible. Options:
      • Use ReactPHP Promises directly in async contexts (e.g., queues, commands).
      • Create a wrapper to adapt ReactPHP Promises to Laravel’s Promise facade (e.g., for HTTP clients).
    • Event Loop: Must be initialized and managed (e.g., via a Laravel service provider or console command).
  • Laravel Extensions:
    • Async Queues: Integrate with Laravel’s queue system (e.g., Illuminate\Bus\PendingDispatch) to run decorators in workers.
    • Real-Time Features: Use with Laravel Echo or Pusher for WebSocket connections.
    • HTTP Clients: Augment Illuminate\Http\Client with async decorators (e.g., for retries or timeouts).

Migration Path

  1. Assess Current Connections:
    • Audit existing fsockopen(), stream_socket_client(), or Guzzle/cURL usage.
    • Identify candidates for async replacement (e.g., external APIs, WebSockets).
  2. Add ReactPHP:
    composer require reactphp/socket reactphp/promise clue/connection-manager-extra
    
  3. Initialize Event Loop:
    • Register a service provider to bootstrap ReactPHP:
      // app/Providers/ReactPHPServiceProvider.php
      public function register()
      {
          $this->app->singleton('react.event_loop', function () {
              return React\EventLoop\Factory::create();
          });
      }
      
  4. Wrap Existing Logic:
    • Replace synchronous calls with async decorators:
      // Before: Blocking
      $stream = stream_socket_client("tcp://example.com:80");
      
      // After: Async with decorators
      $connector = new \React\Socket\Connector($loop);
      $retryConnector = new \ConnectionManager\Extra\ConnectionManagerRepeat($connector, 3);
      $retryConnector->connect('example.com:80')->then(
          function ($stream) { /* success */ },
          function ($e) { /* failure */ }
      );
      
  5. Bridge to Laravel:
    • For HTTP clients, create a custom macro or manager:
      // app/Providers/AppServiceProvider.php
      public function boot()
      {
          \Illuminate\Support\Facades\Http::macro('async', function ($uri) {
              $loop = app('react.event_loop');
              $connector = new \React\Socket\Connector($loop);
              // Apply decorators...
              return new AsyncHttpResponse($connector->connect($uri));
          });
      }
      

Compatibility

  • Laravel Versions: Works with Laravel 8+ (PHP 8.1+ recommended). Older versions may need Promise adapters.
  • PHP Versions: Supports PHP 7.2–8.5 (per changelog). Laravel’s minimum PHP version (8.0+) is compatible.
  • Dependencies:
    • ReactPHP 1.0+: Required for Socket and Promise.
    • No Laravel Core Conflicts: Decorators are agnostic to Laravel’s components but require async context.

Sequencing

  1. Phase 1: Proof of Concept
    • Implement a single decorator (e.g., ConnectionManagerRepeat) in a non-critical endpoint or queue job.
    • Verify ReactPHP integration and error handling.
  2. Phase 2: Core Integration
    • Replace blocking connections in background jobs or real-time features.
    • Add monitoring for connection metrics (e.g., retry rates).
  3. Phase 3: Full Migration
    • Gradually replace synchronous HTTP clients with async decorators.
    • Optimize event loop management (e.g., per-worker vs. global).

Operational Impact

Maintenance

  • Dependency Management:
    • ReactPHP and its components (socket, promise) require regular updates to avoid compatibility issues (e.g., PHP 8.5+ changes).
    • The package itself is MIT-licensed and actively maintained (last release: 2026-04-13), but ReactPHP’s ecosystem may evolve.
  • Debugging:
    • Async stack traces are harder to debug than synchronous code. Tools like Xdebug or ReactPHP’s logging will be critical.
    • Laravel’s exception handler may need extensions to log ReactPHP exceptions.
  • Documentation:
    • Internal docs must clarify:
      • Where async decorators are used (e.g., "only in queue workers").
      • How to cancel pending connections (e.g., PromiseInterface::cancel()).
      • Event loop lifecycle (e.g., when to run() or stop() the loop).

Support

  • Team Skills:
    • Requires familiarity with ReactPHP, Promises, and async PHP.
    • Laravel developers may need training on event loops and non-blocking I/O.
  • Vendor Support:
    • ReactPHP has
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.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui