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.
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:
fsockopen()/stream_socket_client() is replaced with async alternatives.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.react/socket). Laravel apps without ReactPHP would need to:
reactphp/socket and reactphp/promise to composer.json.React\EventLoop\Factory::create()) and integrate it with Laravel’s lifecycle (e.g., via service providers or console commands).Promise facade (Guzzle-based) is incompatible. The package uses ReactPHP’s Promise, requiring:
react/promise-timer for timeouts) or custom wrappers to bridge ReactPHP Promises with Laravel’s ecosystem.await in async contexts like queues or jobs).ConnectionException) must be mapped to Laravel’s exception handlers or middleware.ConnectorInterface) and testing promise chains, which may complicate Laravel’s PHPUnit setup.HttpClient with retries) suffice?ConnectionManagerPool) or managed per-request?reactphp/socket and reactphp/promise.Promise facade is incompatible. Options:
Promise facade (e.g., for HTTP clients).Illuminate\Bus\PendingDispatch) to run decorators in workers.Illuminate\Http\Client with async decorators (e.g., for retries or timeouts).fsockopen(), stream_socket_client(), or Guzzle/cURL usage.composer require reactphp/socket reactphp/promise clue/connection-manager-extra
// app/Providers/ReactPHPServiceProvider.php
public function register()
{
$this->app->singleton('react.event_loop', function () {
return React\EventLoop\Factory::create();
});
}
// 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 */ }
);
// 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));
});
}
Socket and Promise.ConnectionManagerRepeat) in a non-critical endpoint or queue job.socket, promise) require regular updates to avoid compatibility issues (e.g., PHP 8.5+ changes).PromiseInterface::cancel()).run() or stop() the loop).How can I help you explore Laravel packages today?