Introduction
Bref provides custom AWS Lambda runtimes that let PHP applications run natively on Lambda. It packages PHP as a Lambda layer, handles request/response translation, and integrates with the Serverless Framework for deployment.
What Bref Does
- Provides PHP runtime layers for AWS Lambda supporting PHP 8.x
- Translates API Gateway and ALB events into PSR-7 or standard PHP requests
- Supports two modes: HTTP applications (web apps) and event-driven functions
- Integrates with Laravel, Symfony, and other PHP frameworks
- Manages deployment through Serverless Framework or AWS CDK
Architecture Overview
Bref publishes pre-compiled PHP binaries as Lambda layers. When a Lambda function is invoked, the Bref runtime bootstraps PHP, receives the event from the Lambda Runtime API, and passes it to your handler. For HTTP workloads, the php-fpm layer runs PHP-FPM as a child process, translating API Gateway events into FastCGI requests. For event-driven workloads, the function layer calls a PHP callable directly. Deployment artifacts are built by the Serverless Framework, which packages your code and references the correct Bref layer ARN.
Self-Hosting & Configuration
- Requires an AWS account with Lambda, API Gateway, and IAM permissions
- serverless.yml defines functions, runtime layers, and event triggers
- PHP extensions are included in the base layer; additional ones available as extra layers
- Environment variables are set in serverless.yml and accessible via getenv()
- Local development supported through
serverless invoke localor Docker-based emulators
Key Features
- Pre-built Lambda layers with PHP-FPM and CLI runtimes for PHP 8.x
- Native support for Laravel (via Laravel Vapor alternative) and Symfony
- Console command execution on Lambda for cron jobs and queue workers
- Static asset handling through S3 with CloudFront integration
- Cold start optimization through smaller deployment packages and layer caching
Comparison with Similar Tools
- Laravel Vapor — Commercial, Laravel-only; Bref is open-source and framework-agnostic
- Vercel PHP — Limited PHP support; Bref provides full PHP-FPM runtime on Lambda
- AWS Lambda Web Adapter — Generic adapter; Bref is purpose-built for PHP with FPM integration
- Serverless Docker (Fargate) — Container-based, always running; Bref is event-driven with per-request billing
FAQ
Q: Which PHP versions does Bref support? A: Bref maintains layers for actively supported PHP versions, currently PHP 8.1 through 8.3.
Q: Can I use Bref with Laravel? A: Yes. Bref has dedicated documentation and packages for running Laravel on Lambda, including queue and scheduler support.
Q: How do I handle static assets? A: Static files are typically served from S3 behind CloudFront. Bref provides tooling to separate assets from the Lambda deployment package.
Q: What about cold starts? A: PHP-FPM cold starts on Lambda typically range from a few hundred milliseconds to about one second. Provisioned concurrency can eliminate them for latency-sensitive workloads.