Octane
Laravel Octane supercharges your application's performance by keeping it loaded in memory and serving requests at incredible speeds. The FrankenPHP variation of our images provides native Octane support with worker mode built-in.
What is Laravel Octane?
Laravel Octane boots your Laravel application once and keeps it in memory, then processes thousands of requests without reloading. This dramatically improves performance compared to traditional PHP execution.
Traditional PHP: Bootstrap → Handle Request → Teardown → Repeat for every request
With Octane: Bootstrap once → Handle unlimited requests
Quick Start
Let's use this example project to get started.
Classic Mode
By default, FrankenPHP runs in classic mode. Your compose file might look something like this:
services:
php:
image: serversideup/php:8.4-frankenphp
ports:
- "80:8080"
volumes:
- .:/var/www/html/
We'll expand upon this classic mode file and modify it to run Laravel Octane (which uses FrankenPHP's worker mode).
Install Laravel Octane
First, install Octane in your Laravel application:
docker compose run php composer require laravel/octane
When that command runs, you should see a PHP file that Laravel creates in your /public directory. This is required for Laravel Octane to work.
<?php
// Set a default for the application base path and public path if they are missing...
$_SERVER['APP_BASE_PATH'] = $_ENV['APP_BASE_PATH'] ?? $_SERVER['APP_BASE_PATH'] ?? __DIR__.'/..';
$_SERVER['APP_PUBLIC_PATH'] = $_ENV['APP_PUBLIC_PATH'] ?? $_SERVER['APP_BASE_PATH'] ?? __DIR__;
require __DIR__.'/../vendor/laravel/octane/bin/frankenphp-worker.php';
It is safe to commit this file to your repository.
Configure Worker Mode
We now want to update the compose file to run Laravel Octane and use proper health checks.
CADDY_* variables). Be sure to review the official Laravel Octane Caddyfile for which variables are supported.services:
php:
image: serversideup/php:8.4-frankenphp
ports:
- "80:8080"
volumes:
- .:/var/www/html/
# Start Octane in worker mode
command: ["php", "artisan", "octane:start", "--server=frankenphp", "--port=8080"]
# Set healthcheck to use our native healthcheck script for Octane
healthcheck:
test: ["CMD", "healthcheck-octane"]
start_period: 10s
We make two major changes here:
- Set the command to start Octane in worker mode - Instead of starting FrankenPHP in classic mode, we start Octane in worker mode.
- Set the healthcheck to use our native healthcheck script for Octane - This is important to ensure that Octane is running and healthy.
Testing Locally
Run your application locally to test Octane:
docker compose up
Your Laravel application will be available at http://localhost with Octane running in worker mode.
Things to Watch Out For
Since Octane is a whole different way of running Laravel compared to traditional PHP-FPM, there are a few things to watch out for.
Dependency Injection
Be careful with how you inject dependencies into long-lived objects. Injecting the wrong things into constructors can cause requests to "leak" between users. Review Laravel's Dependency Injection and Octane documentation for details.
Memory Leaks
Review Laravel's Octane documentation on memory leaks to understand what to avoid.