amphp/http-client
Asynchronous HTTP client for PHP built on Revolt with fibers and concurrency. Supports HTTP/1 & HTTP/2, concurrent requests, connection pooling, redirects, gzip/deflate decoding, streaming bodies, TLS by default, cookies/sessions, proxies, and custom methods—no ext/curl dependency.
Request, Response), easing migration for teams familiar with PSR standards.FollowRedirects, RetryRequests) enables middleware-like customization, similar to frameworks like Laravel’s middleware or Symfony’s HTTP client interceptors.ext/curl Dependency: Eliminates conflicts with existing curl-based clients (e.g., Guzzle) and reduces attack surface.Illuminate\Support\Facades\Http) via custom macros or adapters.phar.ini or php.ini).Amp\run() or Amp\Loop explicitly in Laravel’s service providers or console commands.HttpClientBuilder::setConnectionLimit().Request/Response objects may conflict with immutable PSR-7 expectations in some libraries.HttpClientBuilder::setTlsContext() (security risk).HttpClient in unit tests (e.g., for API service classes)?amphp/http-client conflict with existing AMPHP packages (e.g., amphp/artax) or Laravel’s symfony/http-client?Http facade or use alongside it for async routes.fetchUserDataFromThirdParty).curl dependencies reduce image size.App\Services layer with amphp/http-client.Http facade to support async clients:
// app/Providers/AppServiceProvider.php
use Amp\Http\Client\HttpClientBuilder;
public function boot()
{
\Illuminate\Support\Facades\Http::macro('async', function ($uri, array $options = []) {
$client = HttpClientBuilder::buildDefault();
return $client->request(new \Amp\Http\Client\Request($uri));
});
}
use Amp\Loop;
public function handle()
{
Loop::run(function () {
$client = HttpClientBuilder::buildDefault();
$response = $client->request(new Request('https://api.example.com/data'));
// Process response...
});
}
/webhooks).composer why-not to audit dependency conflicts.LogHttpArchive for HAR files in staging.Amp\Loop").RetryRequests interceptor for Laravel’s exception handling:
$client->intercept(new RetryRequests(
new ExponentialBackoff(100, 3),
new AllowedMethods(['GET', 'POST'])
));
App\Exceptions\Handler.HttpClient behind an interface for easier swaps (e.g., fallback to Guzzle).setConnectionLimit()).nghttp2 FFI for HTTP/2.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Fiber deadlocks | Hangs async requests | Use Amp\delay() for cooperative yielding. |
| Connection pool exhaustion | Timeouts under load | Monitor with HttpClient::getConnectionCount(). |
| TLS handshake failures | Broken HTTPS requests | Validate setTlsContext() in staging. |
| Redirect loops | Infinite retries | Set followRedirects(5) or custom interceptor. |
| Large response buffering | OOM errors | Stream responses with Payload::read(). |
Amp\Loop::run() in Tinker for interactive testing.RUN docker-php-ext-install amphp
Amp\Loop::run() wrappers.How can I help you explore Laravel packages today?