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

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

A non-blocking HTTP application server for PHP based on Amp.

Frequently asked questions about Http Server
Can I use amphp/http-server directly in Laravel without rewriting controllers?
No, Laravel’s synchronous controllers won’t work—you must rewrite them to implement `RequestHandler` or wrap blocking calls in `Amp\async()`. For example, replace `Route::get()` with async handlers like `class AsyncController implements RequestHandler`. Blocking operations (e.g., Eloquent) require async drivers like `amphp/mysql` or offloading to queues.
How do I handle Laravel’s middleware (auth, CORS) with amphp/http-server?
Laravel’s middleware stack can be adapted via PSR-15 middleware or custom adapters. For example, convert `Illuminate\Pipeline` to `amphp/http-server` middleware by implementing `MiddlewareInterface`. Third-party packages like `labrador-kennel/http-cors` also integrate seamlessly. Auth middleware (e.g., `auth:api`) must be rewritten to work with async request lifecycles.
Will amphp/http-server work with Laravel’s Eloquent ORM?
No, Eloquent is blocking by default. Use async database drivers like `amphp/mysql` or `amphp/postgres` instead. For hybrid setups, offload blocking queries to background jobs (e.g., Laravel Queues) or wrap them in `Amp\async()`. Avoid direct Eloquent usage in async handlers to prevent deadlocks or timeouts.
How do I serve static files in Laravel with amphp/http-server?
Use the `amphp/http-server-static-content` package to serve static files non-blockingly. Configure it as a middleware in your server setup. For Laravel’s `public/` folder, mount it via `StaticContent::fromDirectory(__DIR__.'/../public')`. This avoids PHP-FPM overhead and leverages HTTP/2 multiplexing for faster asset delivery.
Is amphp/http-server compatible with Laravel’s session handling?
Laravel’s session system (e.g., `Session::get()`) may conflict with async request lifecycles. Use `amphp/http-server-session` for async-compatible sessions or implement a custom storage backend. Avoid global session state in async handlers; prefer request-scoped storage or Redis-backed sessions with `amphp/redis`.
Can I use WebSockets with Laravel Echo/Pusher alongside amphp/http-server?
Yes, but requires custom integration. Use `amphp/websocket-server` for WebSocket endpoints and bridge Laravel Echo/Pusher events via a custom event dispatcher. For example, listen to Laravel’s `Event::dispatch()` and forward messages to WebSocket clients. This avoids Echo’s sync dependencies while enabling real-time features.
What’s the best way to test amphp/http-server in a Laravel project?
Async code needs unique testing strategies. Use `Amp\wait()` to resolve `Future` objects in tests or mock async dependencies with `Mockery`. Laravel’s `HttpTests` may require refactoring to work with `RequestHandler` interfaces. Test WebSocket connections with `amphp/websocket-test` and HTTP routes via `GuzzleHttp` clients targeting the async server.
Do I need RoadRunner or Swoole to deploy amphp/http-server with Laravel?
Yes, PHP-FPM won’t work—you need a process manager like **RoadRunner** or **Swoole** to host the async server. RoadRunner’s `async` worker type is ideal for Laravel integration, while Swoole offers lower-level control. Configure your server to proxy requests to `amphp/http-server` via Nginx or directly via `SocketHttpServer`.
How do I handle errors and crashes in amphp/http-server for Laravel?
Unhandled exceptions in async code must be caught and logged manually. Use `try-catch` blocks around `handleRequest()` and log errors via `Amp\Log\ConsoleLogger` or Laravel’s `Log::error()`. For graceful degradation, implement a fallback to sync PHP-FPM (e.g., via a load balancer) or use `amphp/process` to restart failed workers.
Are there alternatives to amphp/http-server for async Laravel?
Yes, consider **Swoole** (full-stack async server with Laravel extensions) or **RoadRunner** (process manager for async workers). Swoole offers tighter Laravel integration (e.g., `swoole-laravel`) but requires PHP extensions. RoadRunner is more portable and works with `amphp/http-server`, but lacks built-in HTTP/2. For pure async APIs, `amphp/http-server` is lighter and more performant than Swoole’s HTTP layer.
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