clue/http-proxy-react
Async HTTP proxy with support for forward and reverse proxying (including HTTPS via CONNECT), built on ReactPHP. Useful for tunneling, debugging and routing HTTP(S) traffic in event-driven PHP apps, with streaming I/O and low overhead.
ConnectorInterface compatibility ensures seamless integration with existing async workflows (e.g., ReactPHP-based HTTP clients or custom TCP handlers).HttpClient with a ReactPHP event loop). This is feasible but non-trivial, as Laravel’s core is not async-native.spatie/laravel-react (for ReactPHP integration).reactphp/http (for async HTTP requests).await in async contexts).spatie/laravel-react to integrate ReactPHP with Laravel’s event loop. This provides:
ReactPHP\LoopInterface integration with Laravel’s service container.HttpClient with reactphp/http for async requests:
$loop = React\EventLoop\Factory::create();
$connector = new React\Http\Browser(new React\Socket\Connector([
'tcp' => new Clue\React\HttpProxy\ProxyConnector('proxy.example.com:8080'),
]), $loop);
laravel-react or custom workers) for async processing.reactphp/socket for WebSocket tunneling.reactphp/grpc with the proxy connector for gRPC traffic.symfony/process) to spawn ReactPHP workers.Phase 1: Proof of Concept
HttpClient call with an async ReactPHP equivalent:
// Before (sync)
$response = Http::get('https://api.example.com/data');
// After (async)
$loop = React\EventLoop\Factory::create();
$browser = new React\Http\Browser($connector, $loop);
$browser->get('https://api.example.com/data')->then(
fn(ResponseInterface $response) => Log::info($response->getBody()),
fn(Exception $e) => Log::error($e->getMessage())
);
$loop->run(); // Blocking; use a worker process in production.
spatie/laravel-react to manage the event loop in Laravel.Phase 2: Gradual Adoption
// Worker.php
$loop = React\EventLoop\Factory::create();
$connector = new React\Socket\Connector(['tcp' => new ProxyConnector('proxy.example.com')]);
$browser = new React\Http\Browser($connector, $loop);
while ($job = Job::pop()) {
$browser->get($job->url)->then(
fn($response) => $job->resolve($response),
fn($e) => $job->fail($e)
);
}
$loop->run();
Phase 3: Full Integration
public function handle($request, Closure $next) {
$connector = new React\Socket\Connector(['tcp' => new ProxyConnector(config('proxy.url'))]);
$browser = new React\Http\Browser($connector, app('react.loop'));
return $browser->get($request->url)->then(...);
}
How can I help you explore Laravel packages today?