laravel/octane
Laravel Octane supercharges Laravel by keeping your app in memory and serving requests via high-performance servers like FrankenPHP, RoadRunner, Swoole, and Open Swoole. Boot once, handle many requests fast for lower latency and higher throughput.
Installation:
composer require laravel/octane
php artisan octane:install
Choose your preferred server (FrankenPHP, Swoole, RoadRunner, or Open Swoole) during installation.
First Use Case: Start Octane with your chosen server:
php artisan octane:start
For FrankenPHP (default):
php artisan octane:start frankenphp
Access your app at http://localhost:8000 (default port).
Key Files to Review:
octane.php (config file generated during installation).env (check OCTANE_SERVER, OCTANE_WORKERS, etc.)artisan commands (octane:start, octane:stop, octane:reload)Development Workflow:
php artisan octane:start in development for instant reloads on file changes.php artisan octane:reload manually or via CI/CD hooks.Production Deployment:
octane.php:
'workers' => [
'concurrency' => env('OCTANE_WORKERS', 8),
'memory' => env('OCTANE_MEMORY', '1G'),
],
OCTANE_SERVER=roadrunner
OCTANE_WORKERS=16
OCTANE_MEMORY=2G
Concurrency Patterns:
Octane::concurrently() for parallel tasks:
use Laravel\Octane\Facades\Octane;
Octane::concurrently([
fn() => dispatch(new ProcessPodcast()),
fn() => dispatch(new SendNotifications()),
]);
Octane::task() for fire-and-forget background jobs:
Octane::task(fn() => $this->processHeavyTask());
Server-Specific Patterns:
OCTANE_CADDY_EXTRA_CONFIG:
OCTANE_CADDY_EXTRA_CONFIG=@import /path/to/custom.conf
roadrunner.json (merged with Octane’s defaults).php artisan octane:start roadrunner --config=custom.json.octane.php or .env:
OCTANE_SWOOLE_WORKERS=auto
OCTANE_SWOOLE_TASK_WORKERS=4
Integration with Laravel Features:
php artisan octane:queue for concurrent queue processing.Octane::actingAs() for authenticated tests:
Octane::actingAs($user)->get('/dashboard');
CI/CD Integration:
php artisan octane:test to run tests with Octane’s server.- name: Run Octane Tests
run: php artisan octane:test --server=swoole --workers=2
Memory Leaks:
OCTANE_MEMORY conservatively in production (e.g., 1G per worker).php artisan octane:stop --force to kill stuck processes.File Watcher Quirks:
node_modules, vendor, and .git by default. Add exclusions via:
OCTANE_WATCH_EXCLUDES=storage/logs,bootstrap/cache
php artisan octane:reload or integrate with nodemon/entr.Configuration Overrides:
.env variables may not override octane.php as expected.php artisan octane:install --keep-config to preserve custom configs during updates.Database Connections:
octane:reload.AppServiceProvider:
public function boot()
{
if (app()->runningInConsole() && !app()->runningUnitTests()) {
DB::disconnect();
}
}
Streaming Responses:
StreamResponse:
return response()->stream(fn() => yield $data);
Debugging:
http://localhost:2019 (default port).rr get-stats to monitor workers.php artisan octane:logs.Performance Tuning:
OCTANE_CADDY_EXTRA_CONFIG=encode gzip brotli
OCTANE_SWOOLE_MAX_REQUESTS to limit worker lifespan:
OCTANE_SWOOLE_MAX_REQUESTS=1000
Custom Servers:
Laravel\Octane\Server:
class CustomServer implements Server {
public function run(): void { /* ... */ }
}
octane.php:
'servers' => [
'custom' => \App\Octane\CustomServer::class,
],
Dependency Injection:
Octane::boost() to optimize service containers:
Octane::boost(function () {
return new \App\Services\HeavyService();
});
Environment-Specific Configs:
$server = config('octane.server');
$config = require __DIR__."/config/octane/{$server}.php";
Testing:
Octane::fake():
Octane::fake();
$response = Octane::actingAs($user)->get('/');
Octane::assertConcurrentTasksRan();
Logging:
OCTANE_LOG_CHANNEL=single
OCTANE_LOG_FILE=/var/log/octane.log
Security:
OCTANE_ADMIN_HOST=127.0.0.1
Legacy Code:
dd() may not work as expected in Octane.Octane::dumpAndDie() or configure FrankenPHP to handle dd():
OCTANE_FRANKENPHP_DUMP_AND_DIE=true
Static Files:
Octane::serveStaticFiles();
Upgrade Notes:
octane.php and .env before upgrading.composer update laravel/octane and php artisan octane:install --keep-config.
How can I help you explore Laravel packages today?