{"id":23884754,"url":"https://github.com/cachewerk/bref-laravel-bridge","last_synced_at":"2025-08-29T13:29:35.842Z","repository":{"id":39918312,"uuid":"493421588","full_name":"cachewerk/bref-laravel-bridge","owner":"cachewerk","description":"An advanced Laravel integration for Bref, including Octane support.","archived":false,"fork":false,"pushed_at":"2023-03-07T17:22:27.000Z","size":93,"stargazers_count":40,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-23T01:52:05.643Z","etag":null,"topics":["bref","laravel","laravel-octane","serverless-framework"],"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/cachewerk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2022-05-17T21:40:16.000Z","updated_at":"2025-05-16T20:22:25.000Z","dependencies_parsed_at":"2025-04-09T22:37:50.114Z","dependency_job_id":null,"html_url":"https://github.com/cachewerk/bref-laravel-bridge","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/cachewerk/bref-laravel-bridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachewerk%2Fbref-laravel-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachewerk%2Fbref-laravel-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachewerk%2Fbref-laravel-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachewerk%2Fbref-laravel-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cachewerk","download_url":"https://codeload.github.com/cachewerk/bref-laravel-bridge/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachewerk%2Fbref-laravel-bridge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272692122,"owners_count":24977289,"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","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bref","laravel","laravel-octane","serverless-framework"],"created_at":"2025-01-04T03:17:57.667Z","updated_at":"2025-08-29T13:29:35.824Z","avatar_url":"https://github.com/cachewerk.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bref Laravel Bridge\n\nAn advanced Laravel integration for Bref, including Octane support.\n\nThis project is largely based on code from [PHP Runtimes](https://github.com/php-runtime/runtime), [Laravel Vapor](https://github.com/laravel/vapor-core) and [Bref's Laravel Bridge](https://github.com/brefphp/laravel-bridge).\n\n## Background\n\nWhy does this exist and why not just use [Laravel Vapor](https://vapor.laravel.com)? Vapor is fantastic, easy to use and the better choice for situations, its $399/year pay for itself not having to maintain your own infrastructure.\n\nFor [Relay](https://relay.so)'s API however we needed something that 1) **is open source** _(Vapor's API is a black box)_, 2) **is secure** _(Vapor has admin access to databases and environment variables)_ and 3) doesn't leave us at the **mercy of a support team** _(Vapor has no enterprise support)_. We also didn't want to be forced to use CloudFront on top of Cloudflare, but that's just nerdy preference.\n\nWe needed an open source solution that gives us more fine-grained control and is secure.\n\n[Bref](https://bref.sh) + [Serverless Framework](https://www.serverless.com/) is exactly that, however Bref's Laravel integration is rather basic, it easily exposes SSM secrets and it doesn't support Laravel Octane.\n\nSo we built this.\n\n## Installation\n\nFirst, be sure to familiarize yourself with Bref and its guide to [Serverless Laravel applications](https://bref.sh/docs/frameworks/laravel.html).\n\nNext, install the package and publish the custom Bref runtime:\n\n```\ncomposer require cachewerk/bref-laravel-bridge\n\nphp artisan vendor:publish --tag=bref-runtime\n```\n\nBy default the runtime is published to `php/` where Bref's PHP configuration resides, but it can be move anywhere.\n\nNext, we need to set up in the `AWS_ACCOUNT_ID` environment variable in your `serverless.yml`:\n\n```yml\nprovider:\n  environment:\n    AWS_ACCOUNT_ID: ${aws:accountId}\n```\n\nThen set up your functions:\n\n```yml\nfunctions:\n  web:\n    handler: php/runtime.php\n    environment:\n      APP_RUNTIME: octane\n      BREF_LOOP_MAX: 250\n    layers:\n      - ${bref:layer.php-81}\n    events:\n      - httpApi: '*'\n\n  queue:\n    handler: php/runtime.php\n    timeout: 59\n    environment:\n      APP_RUNTIME: queue\n    layers:\n      - ${bref:layer.php-81}\n    events:\n      - sqs:\n          arn: !GetAtt Queue.Arn\n          batchSize: 1\n          maximumBatchingWindow: 60\n\n  cli:\n    handler: php/runtime.php\n    timeout: 720\n    environment:\n      APP_RUNTIME: cli\n    layers:\n      - ${bref:layer.php-81}\n      - ${bref:layer.console}\n    events:\n      - schedule:\n          rate: rate(1 minute)\n          input: '\"schedule:run\"'\n```\n\nIf you don't want to use Octane, simply remove `APP_RUNTIME` and `BREF_LOOP_MAX` from the `web` function.\n\nTo avoid setting secrets as environment variables on your Lambda functions, you can inject them directly into the Lambda runtime:\n\n```yml\nprovider:\n  environment:\n    APP_SSM_PREFIX: /${self:service}-${sls:stage}/\n    APP_SSM_PARAMETERS: \"APP_KEY, DATABASE_URL\"\n```\n\nThis will inject `APP_KEY` and `DATABASE_URL` using your service name and stage, for example from `/myapp-staging/APP_KEY`.\n\nFinally, deploy your app:\n\n```\nsls deploy --stage=staging\n```\n\nCheck out some more [comprehensive examples](examples/).\n\n## Configuration\n\n### Serving static assets\n\nIf you want to serve some static assets from your app's `public` directory, you can use the `ServeStaticAssets` middleware.\n\nFirst, publish the configuration:\n\n```\nphp artisan vendor:publish --tag=bref-config\n```\n\nThen define the files you want to serve in `bref.assets`.\n\nLastly tell Bref to support binary responses on your `web` function:\n\n```yml\nfunctions:\n  web:\n    handler: php/runtime.php\n    environment:\n      BREF_BINARY_RESPONSES: 1\n```\n\n### Persistent database sessions\n\nIf you're using PostgreSQL 9.6 or newer, you can take advantage of persistent database sessions.\n\nFirst set [`idle_in_transaction_session_timeout`](https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-IDLE-IN-TRANSACTION-SESSION-TIMEOUT) either in your RDS database's parameter group, or on a specific database itself.\n\n```sql\nALTER DATABASE SET idle_in_transaction_session_timeout = '10000' -- 10 seconds in ms\n```\n\nLastly, set the `OCTANE_PERSIST_DATABASE_SESSIONS` environment variable.\n\n```yml\nfunctions:\n  web:\n    handler: php/runtime.php\n    environment:\n      APP_RUNTIME: octane\n      BREF_LOOP_MAX: 250\n      OCTANE_PERSIST_DATABASE_SESSIONS: 1\n```\n\n## Usage\n\n### Artisan Console\n\nJust like with Bref, you may [execute console commands](https://bref.sh/docs/runtimes/console.html).\n\n```\nvendor/bin/bref cli \u003cservice\u003e-\u003cstage\u003e-cli -- route:list\n\nvendor/bin/bref cli example-staging-cli -- route:list\n```\n\n### Maintenance mode\n\nSimilar to the `php artisan down` command, you may put your app into maintenance mode. All that's required is setting the `MAINTENANCE_MODE` environment variable:\n\n```yml\nprovider:\n  environment:\n    MAINTENANCE_MODE: ${param:maintenance, null}\n```\n\nYou can then quickly put all functions into maintenance without running a full build and CloudFormation deploy:\n\n```\nserverless deploy function --function=web --update-config --param=\"maintenance=1\"\nserverless deploy function --function=cli --update-config --param=\"maintenance=1\"\nserverless deploy function --function=queue --update-config --param=\"maintenance=1\"\n```\n\nTo take your app out of maintenance mode, simply omit the parameter: \n\n```\nserverless deploy function --function=web --update-config\nserverless deploy function --function=cli --update-config\nserverless deploy function --function=queue --update-config\n```\n\nOne caveat with the `--update-config` flag is that it doesn't do objects in `environment` variables in the `serverless.yml`:\n\n```yml\nprovider:\n  environment:\n    SQS_QUEUE: ${self:service}-${sls:stage}    # good\n    SQS_QUEUE: !Ref QueueName                  # bad\n    SQS_QUEUE:                                 # bad\n      Ref: QueueName\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcachewerk%2Fbref-laravel-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcachewerk%2Fbref-laravel-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcachewerk%2Fbref-laravel-bridge/lists"}