{"id":19289813,"url":"https://github.com/brefphp/symfony-bridge","last_synced_at":"2026-02-26T18:22:47.234Z","repository":{"id":44047271,"uuid":"254371088","full_name":"brefphp/symfony-bridge","owner":"brefphp","description":"Bref runtime to run Symfony on AWS Lambda","archived":false,"fork":false,"pushed_at":"2024-08-27T12:57:05.000Z","size":124,"stargazers_count":49,"open_issues_count":10,"forks_count":15,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T16:13:25.704Z","etag":null,"topics":["aws-lambda","bref","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brefphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["mnapoli"]}},"created_at":"2020-04-09T12:55:11.000Z","updated_at":"2025-02-26T15:21:30.000Z","dependencies_parsed_at":"2024-02-20T15:30:31.435Z","dependency_job_id":"f783db65-9b9d-4c1d-9a85-01b07be1cc51","html_url":"https://github.com/brefphp/symfony-bridge","commit_stats":{"total_commits":88,"total_committers":8,"mean_commits":11.0,"dds":0.5795454545454546,"last_synced_commit":"a2e67cfb49ee7028e2bb354521d9638a8a212d7d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":"mnapoli/project-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brefphp%2Fsymfony-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brefphp%2Fsymfony-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brefphp%2Fsymfony-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brefphp%2Fsymfony-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brefphp","download_url":"https://codeload.github.com/brefphp/symfony-bridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535519,"owners_count":20954576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","bref","symfony"],"created_at":"2024-11-09T22:17:14.879Z","updated_at":"2026-02-26T18:22:47.212Z","avatar_url":"https://github.com/brefphp.png","language":"PHP","funding_links":["https://github.com/sponsors/mnapoli"],"categories":[],"sub_categories":[],"readme":"[Bref](https://bref.sh/) runtime to run Symfony on AWS Lambda.\n\n[![Build Status](https://github.com/brefphp/symfony-bridge/workflows/Tests/badge.svg)](https://github.com/brefphp/symfony-bridge/actions)\n[![Latest Version](https://img.shields.io/packagist/v/bref/symfony-bridge?style=flat-square)](https://packagist.org/packages/bref/symfony-bridge)\n[![Total Downloads](https://img.shields.io/packagist/dt/bref/symfony-bridge.svg?style=flat-square)](https://packagist.org/packages/bref/symfony-bridge)\n\n## Installation\n\n```cli\ncomposer req bref/symfony-bridge\n```\n\n## Usage\n\nYou only need to do one small change to quickly setup Symfony to work with Bref.\n\n```diff\n// src/Kernel.php\n\nnamespace App;\n\n+ use Bref\\SymfonyBridge\\BrefKernel;\nuse Symfony\\Bundle\\FrameworkBundle\\Kernel\\MicroKernelTrait;\nuse Symfony\\Component\\Config\\Loader\\LoaderInterface;\nuse Symfony\\Component\\Config\\Resource\\FileResource;\nuse Symfony\\Component\\DependencyInjection\\ContainerBuilder;\n-use Symfony\\Component\\HttpKernel\\Kernel as BaseKernel;\nuse Symfony\\Component\\Routing\\RouteCollectionBuilder;\n\n- class Kernel extends BaseKernel\n+ class Kernel extends BrefKernel\n{\n    // ...\n```\n\nNow you are up and running.\n\n## Optimize first request\n\nThe first HTTP request that hits your application after you deployed a new version\nwill use a cold cache directory. Symfony now spends time building thc cache. It may\ntake everything between 1-20 seconds depending on the complexity of the application.\n\nTechnically this happens whenever your application run on a new Lambda. That could\nbe when you get a lot more traffic so AWS increases the resources or when AWS just\ndecides to kill the lambda function (or server) that you are currently on. It is\nnormal that this happens at least a handful of times every day.\n\nTo optimize the first request, one must deploy the application with a warm cache.\nIn a simple application it means that the deploy script should include `cache:warmup`\nto look something like this:\n\n```bash\n# Install dependencies\ncomposer install --classmap-authoritative --no-dev --no-scripts\n\n# Warmup the cache\nbin/console cache:clear --env=prod\n\n# Disable use of Dotenv component\necho \"\u003c?php return [];\" \u003e .env.local.php\n\nserverless deploy\n```\n\n## Optimize cache\n\nWhen running Symfony on Lambda you should avoid writing to the filesystem. If\nyou prewarm the cache before deploy you are mostly fine. But you should also make\nsure you never write to a filesystem cache like `cache.system` or use a pool like:\n\n```yaml\nframework:\n    cache:\n        pools:\n            my_pool:\n                adapter: cache.adapter.filesystem\n```\n\nIf you don't write to such cache pool you can optimize your setup by not copy the\n`var/cache/pools` directory. The change below will make sure to symlink the `pools`\ndirectory.\n\n```diff\n// src/Kernel.php\n\n\nclass Kernel extends BrefKernel\n{\n    // ...\n\n+    protected function getWritableCacheDirectories(): array\n+    {\n+        return [];\n+    }\n}\n```\n\n## Handling requests in a kept-alive process without FPM\n\n\u003e Note: this is an advanced topic. Don't bother with this unless you know what you are doing.\n\nTo handle HTTP requests via the Symfony Kernel, without using PHP-FPM, by keeping the process alive:\n\n```diff\n# serverless.yml\n\nfunctions:\n    app:\n-        handler: public/index.php\n+        handler: App\\Kernel\n        layers:\n            # Switch from PHP-FPM to the \"function\" runtime:\n-            - ${bref:layer.php-80-fpm}\n+            - ${bref:layer.php-80}\n        environment:\n            # The Symfony process will restart every 100 requests\n            BREF_LOOP_MAX: 100\n```\n\nThe `App\\Kernel` will be retrieved via Symfony Runtime from `public/index.php`. If you don't have a `public/index.php`, read the next sections.\n\n## Class handlers\n\nTo handle other events (e.g. [SQS messages with Symfony Messenger](https://github.com/brefphp/symfony-messenger)) via a class name:\n\n```diff\n# serverless.yml\n\nfunctions:\n    sqsHandler:\n-        handler: bin/consumer.php\n+        handler: App\\Service\\MyService\n        layers:\n            - ${bref:layer.php-80}\n```\n\nThe service will be retrieved via Symfony Runtime from the Symfony Kernel returned by `public/index.php`.\n\n\u003e Note: the service must be configured as **public** (`public: true`) in the Symfony configuration.\n\n### Custom bootstrap file\n\nIf you do not have a `public/index.php` file, you can create a file that returns the kernel (or any PSR-11 container):\n\n```php\n\u003c?php\n\nrequire_once dirname(__DIR__).'/vendor/autoload_runtime.php';\n\nreturn function (array $context) {\n    return new App\\Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);\n};\n```\n\nAnd configure it in `serverless.yml`:\n\n```diff\n# serverless.yml\nfunctions:\n    sqsHandler:\n        handler: kernel.php:App\\Service\\MyService\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrefphp%2Fsymfony-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrefphp%2Fsymfony-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrefphp%2Fsymfony-bridge/lists"}