clue/connection-manager-extra
Extra ReactPHP socket connector decorators that implement ConnectorInterface: retry/repeat, timeouts, delays, reject rules, swappable connectors, consecutive/random selection, concurrency limits, and selective routing for async connection management.
Start by installing the package via Composer: composer require clue/connection-manager-extra. This package extends ReactPHP's React\Socket component with advanced decorators for connection management — it does not include ReactPHP itself, so ensure react/socket is also installed. The primary use case is managing persistent, asynchronous TCP/SSL connections in long-running applications (e.g., WebSocket clients, custom TCP servers, or microservices communication). Begin by reviewing the README for the included decorators: TimeoutDecorator, ReconnectDecorator, BufferedConnection, and SecureConnection.
Note (v1.3.0): New shorthand constructors (
ConnectionManagerTimeout,ConnectionManagerDelayed) now infer the default event loop — simplifying usage by removing the need to pass$loopexplicitly. Existing...Decoratorclasses remain supported for backward compatibility.
ReconnectDecorator: Wrap your socket connections to automatically retry on failure with exponential backoff (configurable delays and max retries).
$connector = new ReconnectDecorator($connector, ['delay' => 1000, 'maxAttempts' => 5]);
TimeoutDecorator / ConnectionManagerTimeout:
$connector = new TimeoutDecorator($connector, 5.0, $loop);
$connector = new ConnectionManagerTimeout($connector, 5.0); // $loop optional
$connector = new BufferedConnection($connector);
$connector = new SecureConnection($connector, $context);
$connector = new ReconnectDecorator($connector);
Note:
ConnectionManagerDelayednow accepts optional$loopparameter (inferred if omitted), enabling cleaner delayed-retry patterns without loop propagation boilerplate.
ConnectionManager* variants for new code to leverage simplified APIs.^1.0 (react/socket ^1.3+). While PHP 8.1/8.2 is now fully supported, ensure react/promise v2.x is used for Promise v3 forward compatibility — breaking changes may occur with react/promise ^3.0 until further updates.TimeoutDecorator outside ReconnectDecorator if you want per-retry timeout control; otherwise, timeouts may reset on reconnect. Be consistent: Mix ConnectionManager* and *Decorator classes cautiously — they share core behavior but may differ in parameter handling.BufferedConnection retains unread data until consumed; ensure consumers drain streams or register data handlers promptly.ConnectionManager* boundaries for clearer tracing.ConnectionManager* variants now infer the default loop (Loop::get()), avoid instantiating any decorator outside a running loop context. Explicit loop injection is still advised for testability.ConnectionManager* decorators to inject retry strategies (e.g., jittered exponential backoff), custom error handling, or telemetry integration.How can I help you explore Laravel packages today?