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 Server Laravel Package

amphp/http-server

Non-blocking, concurrent HTTP/1.1 and HTTP/2 application server for PHP 8.1+ built on Revolt and Amp (fibers). Includes TLS, middleware, gzip, and integrations for routing, static files, WebSockets, sessions, and more.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven & Async-First: The package leverages AMPHP’s fiber-based concurrency model, aligning well with modern PHP applications requiring high concurrency (e.g., real-time APIs, WebSockets, or high-traffic microservices). This contrasts with Laravel’s traditional synchronous request lifecycle, necessitating a fundamental shift in how HTTP requests are processed.
  • Protocol Support: Native HTTP/1.1 and HTTP/2 support (including WebSockets) is a strong fit for Laravel applications needing real-time features (e.g., notifications, collaborative tools) or performance-critical APIs.
  • Middleware & Routing: The middleware stack and router integration mirror Laravel’s ecosystem, enabling gradual adoption of async patterns without rewriting core logic.
  • TLS & Compression: Built-in TLS and GZIP compression reduce boilerplate for secure, performant endpoints.

Integration Feasibility

  • Laravel’s Synchronous Core: Laravel’s request lifecycle (e.g., middleware, service containers) is blocking by design. Integrating amphp/http-server requires:
    • Wrapper Layer: A facade to translate Laravel’s Illuminate\Http\Request/Response to Amp\Http\Server\Request/Response.
    • Async Service Container: Laravel’s IoC container must support fiber-aware dependency resolution (e.g., async database calls via amphp/mysql).
    • Event Loop Integration: Laravel’s event system (e.g., Illuminate\Events\Dispatcher) must run cooperatively within AMPHP’s event loop.
  • Database & External Calls: Laravel’s Eloquent/Query Builder uses blocking I/O (e.g., DB::connection()->getPdo()). Replacement with amphp/postgres/amphp/mysql is mandatory to avoid process blocking.
  • Queue Workers: Laravel’s queue system (e.g., Illuminate\Queue) would need async-compatible drivers (e.g., amphp/redis) or fiberized workers.

Technical Risk

  • High Cognitive Load: Developers must understand fibers, coroutines, and non-blocking I/O, which diverges from Laravel’s synchronous paradigm. Risk of deadlocks or resource leaks if blocking calls sneak into async handlers.
  • Dependency Conflicts: AMPHP’s ecosystem (e.g., amphp/socket, amphp/http-client) may conflict with Laravel’s bundled libraries (e.g., Guzzle, Symfony HTTP components).
  • Tooling Gaps: Laravel’s debugging tools (e.g., Tinker, Horizon) assume synchronous execution. Async stack traces and profiling require custom solutions.
  • Cold Starts: PHP’s process-based model may increase latency for async servers compared to traditional Laravel (unless using a pre-warmed pool).

Key Questions

  1. Use Case Justification:
    • Why async? Is the bottleneck I/O-bound (e.g., DB queries, external APIs) or CPU-bound (async won’t help)?
    • Does the app need real-time features (WebSockets) or just higher concurrency?
  2. Migration Strategy:
    • Will integration be incremental (e.g., async routes only) or full rewrite?
    • How will legacy middleware (e.g., auth, CORS) adapt to async?
  3. Performance Tradeoffs:
    • Will fiber overhead outweigh gains from async I/O?
    • How will memory usage compare to traditional Laravel (AMPHP uses more due to coroutines)?
  4. Operational Impact:
    • How will deployments change (e.g., process management, load balancing)?
    • Are there monitoring gaps (e.g., no native support for Laravel Scout/Prometheus)?

Integration Approach

Stack Fit

  • Core Compatibility:
    • Laravel 10+: Best fit due to PHP 8.1+ support and improved fiber compatibility (e.g., Swoole/RoadRunner integrations).
    • Async Drivers: Replace:
      • Illuminate\Databaseamphp/postgres/amphp/mysql.
      • GuzzleHttpamphp/http-client.
      • Redisamphp/redis.
    • WebSocket Support: Use amphp/websocket-server alongside Laravel Echo/Pusher.
  • Existing Ecosystem:
    • Middleware: Laravel’s middleware can be adapted via Middleware interface (e.g., auth, rate limiting).
    • Routing: Use amphp/http-server-router to mirror Laravel’s RouteServiceProvider.
    • Validation: Laravel’s Validator can run synchronously within a fiber (if I/O-bound calls are async-compatible).

Migration Path

  1. Phase 1: Async Routes
    • Isolate async routes (e.g., /ws, /stream) behind a reverse proxy (Nginx) routing to amphp/http-server.
    • Use Laravel’s service container to inject async handlers where needed.
  2. Phase 2: Hybrid Mode
    • Replace blocking I/O (e.g., DB, HTTP clients) with async equivalents.
    • Wrap Laravel’s Request/Response in adapters for Amp\Http\Server.
  3. Phase 3: Full Async
    • Rewrite core request handling to use SocketHttpServer.
    • Replace synchronous queues with async workers (e.g., amphp/parallel).

Compatibility

  • Breaking Changes:
    • No Blocking Calls: Any file_get_contents(), sleep(), or DB::select() will crash the server.
    • Session Handling: Laravel’s file-based sessions won’t work; use amphp/http-server-session with Redis.
  • Workarounds:
    • Legacy Code: Offload blocking tasks to worker processes (e.g., Amp\Parallel).
    • Synchronous Fallback: Use Amp\async() to run legacy code in a separate fiber (with caution).

Sequencing

  1. Infrastructure:
    • Set up AMPHP-compatible PHP runtime (e.g., PHP 8.2+ with ext-fiber).
    • Configure load balancer to handle async workers (e.g., RoadRunner, Swoole).
  2. Dependencies:
    • Replace Laravel’s HTTP/DB clients before migrating routes.
  3. Testing:
    • Stress-test async handlers for memory leaks (fibers can accumulate).
    • Validate WebSocket and streaming endpoints early.

Operational Impact

Maintenance

  • Debugging Complexity:
    • Async stack traces are harder to read (fibers interleave execution).
    • Tools like Xdebug may not work as expected; use Amp\Log for tracing.
  • Dependency Updates:
    • AMPHP ecosystem is less mature than Laravel’s; expect more frequent breaking changes.
  • Configuration:
    • Tuning Required: Adjust SocketHttpServer limits (e.g., concurrentRequests) based on workload.

Support

  • Skill Gaps:
    • Team must learn fibers, coroutines, and event loops.
    • Limited community support compared to Laravel’s ecosystem.
  • Vendor Lock-in:
    • Heavy reliance on AMPHP may complicate future migrations (e.g., back to Swoole).

Scaling

  • Horizontal Scaling:
    • Stateless Design: Async servers scale similarly to traditional Laravel (stateless = easy to shard).
    • Connection Limits: SocketHttpServer imposes defaults (e.g., 1000 concurrent requests); adjust based on traffic.
  • Vertical Scaling:
    • Memory Usage: Fibers increase per-process memory; monitor with memory_get_usage().
    • CPU Bound: Async helps I/O-bound workloads but won’t help CPU-bound tasks (e.g., heavy computations).

Failure Modes

  • Deadlocks:
    • Risk: Blocking calls in fibers (e.g., usleep()) can hang the entire server.
    • Mitigation: Use Amp\delay() for delays; offload blocking work to workers.
  • Resource Exhaustion:
    • Risk: Unbounded fibers (e.g., from recursive async calls) can OOM the process.
    • Mitigation: Limit fiber depth; use Amp\Parallel for CPU-heavy tasks.
  • Connection Leaks:
    • Risk: Unclosed WebSocket/HTTP connections can deplete file descriptors.
    • Mitigation: Implement timeout middleware and connection cleanup.

Ramp-Up

  • Onboarding:
    • Training: Developers need hands-on fiber/coroutine training (e.g., AMPHP’s docs, workshops).
    • Documentation: Create internal runbooks for async debugging (e.g., "How to profile fiber leaks").
  • Tooling:
    • Monitoring: Integrate with Prometheus to track:
      • Active fibers (amp.active_fibers).
      • Request latency (async adds overhead).
    • **CI
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours