keel / framework
Worker-first PHP micro-framework: PSR stack, attribute routing, compiled container.
Requires
- php: >=8.4
- nyholm/psr7: ^1.8
- nyholm/psr7-server: ^1.1
- psr/clock: ^1.0
- psr/container: ^2.0
- psr/event-dispatcher: ^1.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
- psr/simple-cache: ^3.0
Requires (Dev)
- doctrine/dbal: ^4.2
- friendsofphp/php-cs-fixer: ^3.75
- infection/infection: ^0.35.8
- latte/latte: ^3.0
- league/flysystem: ^3.29
- monolog/monolog: ^3.8
- open-telemetry/sdk: ^1.15
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
- spiral/roadrunner-http: ^4.2
- symfony/console: ^7.3|^8.0
- symfony/mailer: ^8.1
- twig/twig: ^3.15
Suggests
- ext-apcu: Shared cache, rate-limit counters and metrics across workers
- ext-curl: Keel\HttpClient\CurlClient
- ext-intl: ICU plural and select patterns in Keel\I18n
- ext-memcached: Keel\Cache\MemcachedCache
- ext-redis: Keel\Redis\RedisProvider: Redis cache, sessions, counters and metrics
- doctrine/dbal: Keel\Database\DbalProvider
- latte/latte: Keel\View\LatteProvider
- league/flysystem: Keel\Storage\FlysystemStorage
- monolog/monolog: PSR-3 logger implementation
- open-telemetry/sdk: Keel\Telemetry\TracingMiddleware (OpenTelemetry spans per request)
- spiral/roadrunner-http: RoadRunner runtime adapter
- symfony/console: Console runtime and keel:* commands (any 7.3+ or 8.x)
- symfony/mailer: Keel\Mail\MailerProvider: SMTP, sendmail or API mail with Mailer::send() and defer()
- twig/twig: Keel\View\TwigProvider
Provides
None
Conflicts
None
Replaces
- keel/container: v1.7.0
- keel/http: v1.7.0
- keel/router: v1.7.0
- keel/validation: v1.7.0
README
Keel is a PHP 8.4+ microframework for APIs and web applications. The same controllers run under PHP-FPM and in long-lived FrankenPHP or RoadRunner workers.
Documentation · Changelog · Русский
Quick start
Create an app with composer create-project keel/skeleton my-app, then start its development server.
cd my-app
composer serve
Open http://127.0.0.1:8080/ to see {"hello":"keel"}. The starter controller also shows how to render a Twig page and validate a JSON request.
Documentation
Keel uses PSR-7 messages, PSR-15 middleware and PHP attributes for routing. For production, it can compile the service container and cache the routes.
- Core · Container · Routing · HTTP and kernel
- Applications · Configuration, discovery and console · Runtimes · Testing
- APIs · Sessions and signed cookies · Authentication and rate limiting · OpenAPI · Health and metrics
- Integrations · Database · Templates · Cache · HTTP client · File storage · Localization · Mail
Keel follows semantic versioning. See API stability for the public API guarantees.
Run the repository example
From the root of this checkout, install the dependencies and start the example server.
composer install php -S 127.0.0.1:8080 -t examples/hello/public examples/hello/public/index.php
In a second terminal, request a page and list the routes.
curl http://127.0.0.1:8080/hello/world php examples/hello/bin/console keel:routes
The console ships keel:routes, keel:compile, keel:cache-clear, keel:debug:container, keel:doctor,
keel:preload, keel:openapi, keel:serve (built-in server or FrankenPHP worker mode with
--watch), keel:install (a component's package, provider, middleware and config in one step),
keel:ai:init (AGENTS.md and llms.txt) and the keel:make:* generators for controllers,
commands, middleware, listeners, health checks, authenticators and policies; see
Application.
Development
composer install
composer test
composer stan
composer cs
composer infection
CI runs the tests on PHP 8.4 and 8.5, PHPStan at level max, php-cs-fixer, and Infection on the container, router, auth, rate limiting, health and metrics (MSI gate 80%).
Packages
keel/framework is the whole thing. Four components are also published on their own as read-only
splits of this repository and are replaced by the framework: keel/container,
keel/router, keel/http
(depends on router and validation) and keel/validation.
Issues and pull requests go here; bin/split vX.Y.Z pushes the splits.
Benchmarks
In-process, same route (GET /json/42, JSON body), production mode with warm caches,
PHP 8.4.21 with opcache, JIT off, Apple Silicon laptop, 30 000 iterations after warm-up.
The number measures framework overhead per request; the SAPI and the network are excluded.
Reproduce with cd benchmarks && composer install && php -d opcache.enable_cli=1 run.php.
| Framework | boot (ms) | µs / request | requests / s | memory after boot |
|---|---|---|---|---|
| Keel 0.1.0 (compiled container, cached routes) | 11.8 | 4.8 | 208 000 | 0.21 MB |
| Slim 4.15 (closure routes, no container) | 5.9 | 4.8 | 206 000 | 0.07 MB |
Symfony 8.1 MicroKernel (FrameworkBundle, #[Route]) |
29.5 | 31.0 | 32 000 | 0.52 MB |
Memory: a production boot loads 30 files (26 classes, 3 cache files, 1 config file), about
0.3 MB of heap without opcache and well under 100 KB with it; Route objects are materialized
only for routes that match, and nothing survives a request: 2000 requests in a row add 0 bytes.
keel:preload generates an opcache.preload script so php-fpm links every class once: with
it a boot allocates 4 KB and loads 3 files, and boot plus first request drops from 12.8 ms to 2.7 ms.
Measure with php -d opcache.enable_cli=1 memory.php and memory-classes.php in benchmarks/.
Under a real server: FrankenPHP 1.12 worker mode (8 workers), oha with 64 connections for 10 s on
the same laptop, same JSON route: Keel 8 486 requests/s, Slim 8 603 requests/s, median latency 5.2 ms
and p99 34 ms for both, every response 200. Reproduce with benchmarks/frankenphp/run.sh.
Keel does more work per request than the Slim app in this table (attribute controller,
argument resolution with type casting, Problem Details handler, container-resolved
middleware) at the same cost. Symfony's number includes its full HttpKernel event cycle
and terminate().
Roadmap
What's next
Feedback from projects using Keel will guide the next release. Queues and schedulers remain outside the framework’s scope.
Released
-
1.7.0 · Request handling. Limited the cost of parsing large JSON objects and fixed idempotent retries for cookie sessions and multipart requests.
-
1.6.0 · Access control and routing. Class and method access rules now apply together. Route constraints also check decoded parameter values.
-
1.5.1 · Security fixes. Isolated cached responses and idempotency keys between clients and tightened request body limits.
-
1.5.0 · Outgoing requests and mail. Added HTTP retries with a circuit breaker, signed URLs and Symfony Mailer integration.
-
1.4.0 · HTTP and workers. Added idempotency keys, JWT/JWKS authentication, Server-Sent Events and tasks that run after the response.
-
1.3.0 · Routing and application services. Added route groups, CSRF protection, access policies, Redis and Memcached support, and
keel:doctordiagnostics. -
1.2.1 · Tooling. Added generators for health checks and authenticators and expanded mutation testing.
-
1.2.0 · Integrations. Added PDO and Doctrine DBAL with health checks, Twig and Latte, a dependency-free PSR-16 cache and a cURL-based PSR-18 client.
-
1.1.0 · Production APIs. Added authentication and rate limiting, health endpoints, Prometheus metrics and OpenAPI 3.1 generation.
keel:serveadded local development with FrankenPHP workers. -
1.0.0 · Stable API. Established the public API covered by semantic versioning.
License
MIT.