What is Octane?
Laravel Octane is a package that dramatically improves the performance of your Laravel application by running it on a high-performance application server. With traditional PHP-FPM, the application boots and shuts down on every request. Octane boots the application once, keeps it in memory, and processes subsequent requests at blazing speed. The key difference from PHP-FPM is that the application boot process — registering service providers, resolving bindings, etc. — runs only once. After that, every request is handled at maximum speed.Supported servers
Octane supports three application servers.Laravel Cloud recommends running Octane with FrankenPHP and provides full managed support out of the box.
Installation and configuration
Install the package
Run the Octane installer
config/octane.php will be generated.
FrankenPHP
When you choose FrankenPHP, Octane automatically downloads the binary. No additional steps are required.RoadRunner
When you choose RoadRunner, Octane automatically downloads the binary.Swoole
Swoole is a PHP extension that must be installed via PECL.Running Octane
Start the server
8000. Open http://localhost:8000 in your browser.
Specify the server
Set the number of workers
Watch for file changes
During development, the server must be restarted to pick up code changes. The--watch flag restarts it automatically whenever a file changes.
Other management commands
Dependency injection caveats
Because Octane keeps the application in memory, service providerregister and boot methods run only once when the server starts. The same application instance is reused across requests, so injecting the container or request into a singleton constructor requires extra care.
Injecting the container
Injecting the container directly into a singleton constructor can leave you with a stale container.app() global helper and Container::getInstance() always return the current container, so they are safe to use.
Injecting the request
Type-hinting
Illuminate\Http\Request in a controller method or route closure is always safe. The request() global helper also returns the current request.Injecting the configuration repository
config() global helper always returns the current configuration repository, so it is safe to use.
Memory leak prevention
Because Octane keeps the application in memory, data accumulated in static properties will grow without bound and eventually exhaust memory.Recycle workers with max-requests
You can mitigate memory leaks by automatically restarting a worker after it handles a certain number of requests. The default is 500 requests.Set a maximum execution time
config/octane.php lets you set the maximum execution time per request. The default is 30 seconds.
Concurrent tasks (Swoole only)
When using Swoole, you can run multiple operations in parallel withOctane::concurrently().
--task-workers.
Ticks and intervals (Swoole only)
Swoole lets you schedule a callback to run at a fixed interval. Register it in your service provider’sboot method.
Octane cache (Swoole only)
The Octane cache is an ultra-fast in-memory cache backed by Swoole tables, capable of up to 2 million read/write operations per second.Interval cache
An interval cache entry refreshes its value automatically at a fixed interval.Swoole tables (Swoole only)
You can define arbitrary in-memory tables that are accessible from every worker process. Configure them inconfig/octane.php under the tables key.
Octane::table() method.
Production deployment
Nginx + Octane
In production, Octane typically runs behind Nginx. Nginx handles static file serving and SSL termination, then proxies dynamic requests to Octane.Keep Octane running with Supervisor
Use Supervisor in production to ensure Octane stays running continuously.Enable HTTPS
To generate HTTPS URLs through Octane, add the following to your.env file.
Laravel Cloud integration
Laravel Cloud provides fully managed Octane support using FrankenPHP. No Nginx or Supervisor configuration is needed — just two steps to enable Octane.1
Install the package
Install Octane. Running
octane:install is optional but harmless.2
Enable Octane in Laravel Cloud
Open your environment’s App compute cluster settings, turn on “Use Octane as runtime”, then save and deploy. Laravel Cloud automatically builds and starts your application with FrankenPHP + Octane.