Supercharging Laravel Performance with Octane and FrankenPHP
Overview
Prerequisites
Before moving forward, ensure you have the following in your environment:
- PHP8.2 or higher
- Composerfor package management
- Basic familiarity with the Laraveldirectory structure
- A terminal environment capable of running binary files
Key Libraries & Tools
- Laravel Octane: The core package that integrates high-performance servers withLaravel.
- FrankenPHP: A modernPHPapp server built on top of theCaddyweb server.
- Pest: A testing framework focused on simplicity and speed.
- Pest Stressless: A plugin forPestused to perform stress testing and performance benchmarking.
Code Walkthrough
First, initialize a new project. We skip the starter kits to keep the setup lean and choose
laravel new my-octane-app
Next, install the
composer require laravel/octane
Now, run the installation command. When prompted for the server type, select frankenphp. The installer automatically downloads the necessary
php artisan octane:install
Finally, fire up the server. You will receive a local URL where your application is now running in a persistent state.
php artisan octane:start
Syntax Notes
When using ./vendor/bin/pest stress http://localhost:8000 --concurrency=5 tells the plugin to hit the endpoint with five simultaneous users. Note how the CLI output provides real-time feedback on request duration and successful hits.
Practical Examples
In a standard setup, a single request might take 30-50ms to boot the framework. With
Tips & Gotchas
Since Octane::forget method to clear state. If you make code changes, remember that --watch flag during development.
