Skip to Content
DocumentationLaravelLaravel Octane

Laravel Octane

To run the HTTP application with Laravel Octaneย  instead of PHP-FPM, change the following options in the web function:

serverless.yml
functions: web: handler: Bref\LaravelBridge\Http\OctaneHandler runtime: php-84 environment: BREF_LOOP_MAX: 250 # ...

Keep the following details in mind:

  • Laravel Octane does not need Swoole or RoadRunner on AWS Lambda, so it is not possible to use Swoole-specific features.
  • Octane keeps Laravel booted in a long-running process, beware of memory leaksย .
  • The process is kept alive between requests, but you still donโ€™t pay for time between requests. The execution model and cost model of AWS Lambda does not change (Lambda is frozen between requests).
  • BREF_LOOP_MAX specifies the number of HTTP requests handled before the PHP process is restarted (and the memory is cleared).

If you deploy using container images, you must escape the \ characters in your Dockerfile:

Dockerfile
CMD ["Bref\\LaravelBridge\\Http\\OctaneHandler"]

Persistent database connections

You can keep database connections persistent across requests to make your application even faster. To do so, set the OCTANE_PERSIST_DATABASE_SESSIONS environment variable:

serverless.yml
functions: web: handler: Bref\LaravelBridge\Http\OctaneHandler runtime: php-84 environment: BREF_LOOP_MAX: 250 OCTANE_PERSIST_DATABASE_SESSIONS: 1 # ...

Note that if you are using PostgreSQL (9.6 or newer), you need to set idle_in_transaction_session_timeout either in your RDS databaseโ€™s parameter group, or on a specific database itself.

ALTER DATABASE my_database SET idle_in_transaction_session_timeout = '10000'; -- 10 seconds in ms
Last updated on