trunk / core
An async, API-centric PHP framework built on ReactPHP
Requires
- php: >=8.1
- firebase/php-jwt: ^6.10 || ^7.0
- psr/container: ^1.0 || ^2.0
- psr/http-message: ^1.0 || ^2.0
- psr/log: ^1.0 || ^2.0 || ^3.0
- react/child-process: ^0.6.7
- react/http: ^1.9
- react/mysql: ^0.7 || ^0.8
- react/promise: ^3.0
- vlucas/phpdotenv: ^5.5
- voryx/pgasync: ^2.2
- webonyx/graphql-php: ^15.0
Requires (Dev)
- phpunit/phpunit: ^10.5
- react/async: ^4.3
README
Trunk
An async, API-centric PHP framework built on ReactPHP.
Trunk runs your API on a single, non-blocking event loop instead of PHP-FPM's one-process-per-request model. The router, middleware pipeline, ORM, sessions, and CLI all share that loop, so a slow database query doesn't tie up an entire worker - it ties up nothing, because nothing is blocked while it's in flight.
Features
- DI container with constructor autowiring by reflection, plus singleton/factory bindings.
- Router with path params, route model binding, and per-route middleware.
- Validation via
FormRequestclasses that short-circuit to a422before your handler runs. - Database layer for MySQL and PostgreSQL behind one API, with a migrations system (
Schema/BlueprintDSL) and a Data Mapper ORM. - JWT authentication and a CORS/JSON-body-parsing/logging/session middleware stack, on by default.
- Events, object-typed, with config-driven listener registration and a non-blocking
dispatchAsync(). - GraphQL endpoint (via
webonyx/graphql-php's async promise adapter) sharing the same ORM queries as REST. - gRPC client support via a child-process bridge - PHP can't run a gRPC server, so this lets you call one without blocking the loop.
- Console (
php trunk ...) for the dev server, code generation, and migrations.
Installation
Trunk is consumed through a skeleton application, not installed standalone. See the skeleton's README to get a project running, or Getting Started for the full walkthrough.
Documentation
The full guide lives in docs/ - run npm install && npm run docs:dev inside that directory for the local site, or just read the Markdown directly:
- Getting Started
- Routing · Middleware · Validation
- Database & Migrations · Authentication
- Events · GraphQL · gRPC Client
- Console (CLI) · Testing
Testing
composer install
composer test
License
MIT