Download the PHP package prsw/amphp-bundle without Composer
On this page you can find all versions of the php package prsw/amphp-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package amphp-bundle
AmphpBundle
Replaces PHP-FPM with a long-running async HTTP server for Symfony. All I/O is non-blocking and fiber-based. No more PHP-FPM process overhead.
Features
- Async HTTP server — built on amphp/http-server
- Async Doctrine — non-blocking MySQL/PostgreSQL driver with connection pooling
- WebSocket server — attribute-driven endpoints, no Symfony boot for handshake
- SSE streaming — server-sent events via
SseResponse - Generator-based streaming — async
StreamedResponsewithyield - Hot reload —
--dev --watchrestarts on file changes (requiresfswatch) - Cluster mode — multi-worker with process supervision and graceful restart
- Prometheus metrics —
/metricsendpoint withMetricCollectorInterface - Liveness / Readiness probes —
/healthz(no Symfony boot),/readyz(full stack) - Async Redis — cache, session handler, messenger transport
- Async Mailer — SMTP + HTTP via
amphp/http-client
Quick Start
1. Install
Register the bundle if you are not using symfony flex in config/bundles.php:
2. Start the Server
Press Ctrl+C to stop.
3. Add a WebSocket Endpoint
Create a class with the #[WebsocketEndpoint] attribute — no YAML needed:
The bundle auto-discovers #[WebsocketEndpoint] handlers at startup.
CLI Options
| Option | Short | Description | Default |
|---|---|---|---|
--workers |
-w |
Number of worker processes | CPU count |
--max-requests |
-r |
Requests per worker before restart | 1000 |
--host |
Bind address | 127.0.0.1 |
|
--port |
-p |
Bind port | 8080 |
--shutdown-timeout |
-t |
Drain timeout (seconds) | 1 |
--dev |
Single worker, --env=dev, --debug=true |
||
--watch |
File watcher + auto-restart (needs --dev) |
Configuration
DBAL pool settings from
amphp.dbalare automatically wired into Doctrine'sdriverOptions. Keepmax_connectionsbelow your MySQL server's limit (SHOW VARIABLES LIKE 'max_connections'; default 151).
Per-Request Cleanup (Priority Reset System)
After each request, the bundle runs a chain of resetters to release resources and
prevent state leaking between requests. Built-in resetters handle the Doctrine
connection pool and debug logger; you can add your own via PriorityResetInterface.
How It Works
SymfonyRequestHandlercallsRequestResetter::reset()in thefinallyblock.RequestResettersorts all tagged services by priority (highest first) and callsreset()on each.- Built-in priorities:
- User-defined — -255 to 255 (your custom resetters)
DebugLoggerResetter— -255 (clears debug logs)
Adding a Custom Resetter
Create a class implementing PriorityResetInterface:
That's it — no manual tagging or service registration needed. The bundle's
BootstrapIntegrationPass auto-configures any service implementing
PriorityResetInterface with the amphp.resetter tag, and RequestResetter
discovers it automatically via the tagged iterator.
Execution Order
Higher priority numbers run first. Use the built-in constants as anchor points:
| Priority | Resetter | When it runs |
|---|---|---|
| 50 | User example | Custom pool release |
| 0 | User example | General-purpose cleanup |
| -255 | DebugLoggerResetter |
Clear debug logs (last) |
Real-World Use Cases
- Release custom connection pools (Redis, RabbitMQ, gRPC)
- Clear in-memory caches or request-scoped state
- Reset rate-limit counters or circuit breakers
- Close temporary file handles or streams
Built-in Endpoints
| Path | Type | Description |
|---|---|---|
/healthz |
AMPHP middleware | Returns {"status":"alive"} — no Symfony boot |
/readyz |
Symfony route | Full-stack readiness check |
/metrics |
Symfony route | Prometheus metrics |
| user-defined | WebSocket | #[WebsocketEndpoint] handlers |
Benchmarks
Results with wrk -t1 -c100 -d30s, 1 worker, APP_ENV=prod, APP_DEBUG=0:
| Endpoint | Requests/s | Avg Latency | Description |
|---|---|---|---|
/twig-test |
1,446 | 69 ms | Twig template render, no DB |
/products |
392 | 254 ms | Doctrine DBAL query + Twig render (15 rows) |
Compared to PHP-FPM with the same Symfony app, the async server eliminates the PHP-FPM process spawn overhead and connection pool contention, yielding higher throughput under concurrent load.
SSE Streaming
Generator-Based Streaming
Prometheus Metrics
Implement MetricCollectorInterface (autotagged amphp.metric_collector):
Optional Integrations
| Feature | Packages |
|---|---|
| Async Doctrine (MySQL/PostgreSQL) | amphp/mysql + doctrine/orm |
| Async Redis cache / sessions / messenger | amphp/redis |
| Async Mailer (SMTP + HTTP) | symfony/mailer + amphp/http-client |
| WebSocket server | included with the bundle |
Hot reload (--watch) |
fswatch (system package) |
All versions of amphp-bundle with dependencies
ext-pcntl Version *
ext-posix Version *
symfony/dotenv Version ^8.0
symfony/http-kernel Version ^8.0
symfony/http-foundation Version ^8.0
amphp/http-server Version ^3.0
amphp/http-server-form-parser Version ^2.0
amphp/http-server-router Version ^2.0
amphp/http-server-static-content Version ^2.0
amphp/websocket-server Version ^4.0
amphp/socket Version ^2.0
amphp/cluster Version ^2.0
amphp/file Version ^3.2
psr/log Version ^3.0
monolog/monolog Version ^3.0