Documentation
Laravel
Laravel Octane

Laravel Octane

To run the HTTP application with Laravel Octane (opens in a new tab) instead of PHP-FPM, change the following options in the web function:

functions:
    web:
        handler: Bref\LaravelBridge\Http\OctaneHandler
        runtime: php-81
        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 (opens in a new tab).
  • 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:

functions:
    web:
      handler: Bref\LaravelBridge\Http\OctaneHandler
      runtime: php-81
      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 (opens in a new tab) either in your RDS database's parameter group, or on a specific database itself.

ALTER DATABASE SET idle_in_transaction_session_timeout = '10000' -- 10 seconds in ms