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

Http Client Laravel Package

amphp/http-client

Asynchronous HTTP client for PHP built on Revolt and fibers. Supports HTTP/1 & HTTP/2, concurrent requests, connection pooling, redirects, gzip/deflate, streaming bodies, TLS by default, forms, cookies, and proxies—no ext/curl dependency.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Async-First Design: Aligns perfectly with modern PHP architectures leveraging AMPHP’s fiber-based concurrency model, enabling non-blocking I/O for high-throughput applications (e.g., APIs, microservices, or real-time systems).
  • Protocol Flexibility: Supports HTTP/1.1 and HTTP/2 natively, making it ideal for performance-critical or modern web service integrations (e.g., GraphQL, REST APIs with streaming).
  • Composability: Interceptor pattern (e.g., FollowRedirects, RetryRequests) enables modular middleware for cross-cutting concerns like caching, auth, or observability, reducing boilerplate.
  • PSR-7 Compatibility: While not PSR-7 immutable, the API is close enough to integrate with existing PSR-7 tooling (e.g., middleware) via adapters or interceptors.

Integration Feasibility

  • No ext/curl Dependency: Eliminates runtime conflicts with curl-based libraries (e.g., Guzzle) and avoids PHP’s GIL limitations for concurrent requests.
  • Laravel Compatibility:
    • Async Support: Requires Laravel 10+ (with spatie/laravel-async or amphp/laravel) or a custom Swoole/ReactPHP integration layer.
    • Sync Fallback: Can coexist with sync HTTP clients (e.g., Guzzle) via adapters or dual-stack implementations.
    • Queue Workers: Ideal for async job processing (e.g., Laravel Queues) where blocking I/O is costly.
  • Database/ORM Synergy: Streams and connection pooling reduce memory pressure for bulk data fetches (e.g., Eloquent batch operations).

Technical Risk

  • Fiber Adoption Barrier:
    • Laravel’s Sync Default: Requires explicit async opt-in (e.g., via Amp\run() or Swoole). Risk of mixed sync/async code leading to deadlocks or performance cliffs.
    • Middleware Conflicts: Existing Laravel middleware (e.g., auth, CORS) may need rewrites to work with AMPHP’s mutable Request/Response objects.
  • HTTP/2 Overhead:
    • nghttp2 FFI Dependency: Adds binary compatibility risks (e.g., PHP extensions not pre-installed on shared hosting).
    • Connection Management: HTTP/2 multiplexing requires careful tuning to avoid resource exhaustion (e.g., too many concurrent streams).
  • Debugging Complexity:
    • Async Stack Traces: Harder to debug than sync code (e.g., no xdebug integration for fibers).
    • Stateful Interceptors: Misconfigured interceptors (e.g., infinite redirects) can cause silent failures or memory leaks.

Key Questions

  1. Async Strategy:
    • Will the app use AMPHP fibers, Swoole, or ReactPHP? How will this integrate with Laravel’s sync layers?
    • Are there blocking dependencies (e.g., sync DB drivers) that could deadlock async code?
  2. Middleware Adaptation:
    • How will existing Laravel middleware (e.g., Illuminate\Auth) be adapted to work with mutable Request objects?
    • Will interceptors replace middleware, or will a dual-layer approach be needed?
  3. Performance Tradeoffs:
    • Is HTTP/2’s reduced latency worth the complexity vs. HTTP/1.1’s simplicity?
    • How will connection pooling interact with Laravel’s service container (e.g., singleton HttpClient instances)?
  4. Observability:
    • How will logging, metrics, and tracing (e.g., OpenTelemetry) be implemented in an async context?
    • Will the LogHttpArchive interceptor meet compliance needs (e.g., GDPR, audit logs)?
  5. Fallback Strategy:
    • What’s the degradation path if async fails (e.g., fall back to Guzzle or sync HTTP)?
    • How will retries and circuit breakers (e.g., RetryRequests interceptor) be configured?

Integration Approach

Stack Fit

  • Core Stack:
    • PHP 8.1+: Required for fibers and named arguments.
    • AMPHP 3.x: Core async runtime (amphp/amp, amphp/byte-stream).
    • Laravel 10+: With spatie/laravel-async or custom Swoole/AMPHP bridge.
    • Optional:
      • nghttp2 (FFI): For HTTP/2 performance.
      • amphp/http-client-cookies: For session management.
      • amphp/http-client-cache: For caching interceptors.
  • Alternatives:
    • Swoole: If AMPHP’s fibers are too restrictive, Swoole’s coroutines offer similar async benefits with Laravel integration.
    • ReactPHP: For apps already using React’s event loop.

Migration Path

  1. Phase 1: Async Proof of Concept
    • Isolate a non-critical service (e.g., third-party API calls, background jobs).
    • Replace Guzzle with amphp/http-client in a new async worker (e.g., Laravel Queue job).
    • Use Amp\run() to test fiber compatibility.
  2. Phase 2: Middleware Adaptation
    • Rewrite sync middleware as interceptors (e.g., auth → ModifyRequest).
    • Create adapters for PSR-7 middleware (e.g., amphp/artax compatibility layer).
  3. Phase 3: Full Async Integration
    • Migrate HTTP-heavy routes to async handlers (e.g., using spatie/laravel-async).
    • Replace sync HTTP clients (e.g., Guzzle in services) with HttpClient.
    • Configure connection pooling and interceptors globally (e.g., via Laravel service provider).
  4. Phase 4: Observability & Fallbacks
    • Implement LogHttpArchive for debugging.
    • Add circuit breakers (e.g., RetryRequests with exponential backoff).
    • Define sync fallbacks for critical paths (e.g., admin panels).

Compatibility

Component Compatibility Mitigation
Laravel Middleware Low (mutable Request/Response) Rewrite as interceptors or use adapters (e.g., amphp/artax).
Guzzle/Psr\HttpClient Medium (API differences) Use amphp/artax for PSR-7 compatibility or write request/response adapters.
Database (Eloquent) High (async DB drivers like amphp/pdo can work alongside) Ensure DB calls are async (e.g., Amp\wait() for queries).
Queue Workers High (ideal for async I/O) Use Amp\run() in job handles.
HTTP Proxies High (supports amphp/http-tunnel) Configure via HttpClientBuilder.
Caching (Redis) High (async Redis drivers like spatie/async-redis) No blocking calls.

Sequencing

  1. Start with Background Jobs:
    • Replace sync GuzzleHttp\Client in Laravel Queues with HttpClient.
    • Example: Async webhook processing or batch API calls.
  2. API Routes:
    • Use spatie/laravel-async to wrap HTTP-heavy routes (e.g., /search).
    • Example: Concurrent calls to multiple microservices.
  3. Service Layer:
    • Replace Guzzle in service classes (e.g., ThirdPartyApiService).
    • Example: Async payment processing.
  4. Middleware:
    • Last step: Adapt auth/CORS middleware to interceptors or use PSR-7 adapters.

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Interceptors replace repetitive middleware logic (e.g., retries, timeouts).
    • Centralized Config: HttpClientBuilder centralizes settings (e.g., timeouts, redirects) in one place.
    • No curl Dependencies: Eliminates PHP extension conflicts.
  • Cons:
    • Learning Curve: Fibers and async debugging require new skills (e.g., Amp\wait(), coroutine context).
    • Tooling Gaps: Limited IDE support for fibers (e.g., no xdebug step-through).
    • Interceptor Debugging: Harder to trace issues in composed interceptors than linear middleware.

Support

  • Pros:
    • Community: AMPHP ecosystem (amphp/http-client-cache, amphp/http-tunnel) provides battle-tested extensions.
    • MIT License: No vendor lock-in; can fork or extend.
  • Cons:
    • **Lim
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata