Overview Laravel Octane boosts your application performance by serving requests using high-performance application servers. By keeping your application in memory, it eliminates the overhead of booting the framework on every request. The newest addition to the Octane ecosystem is FrankenPHP, a modern server written in Go that offers exceptional speed and features like automatic HTTPS. This integration represents a massive leap forward for developers seeking sub-millisecond response times. Prerequisites Before moving forward, ensure you have the following in your environment: * PHP 8.2 or higher * Composer for package management * Basic familiarity with the Laravel directory structure * A terminal environment capable of running binary files Key Libraries & Tools * **Laravel Octane**: The core package that integrates high-performance servers with Laravel. * **FrankenPHP**: A modern PHP app server built on top of the Caddy web server. * **Pest**: A testing framework focused on simplicity and speed. * **Pest Stressless**: A plugin for Pest used 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 SQLite for rapid prototyping. ```bash laravel new my-octane-app ``` Next, install the Octane package via Composer. This provides the necessary scaffolding to bridge Laravel and FrankenPHP. ```bash composer require laravel/octane ``` Now, run the installation command. When prompted for the server type, select `frankenphp`. The installer automatically downloads the necessary FrankenPHP binary for your architecture. ```bash 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. ```bash php artisan octane:start ``` Syntax Notes When using Pest Stressless to verify performance, the syntax is remarkably clean. Running `./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 FrankenPHP and Octane, benchmark results show response times as low as 0.93ms. This is ideal for high-traffic APIs or real-time dashboards where latency must be kept to an absolute minimum. Tips & Gotchas Since Octane keeps your app in memory, global variables or static properties do not reset between requests. Always use dependency injection or the `Octane::forget` method to clear state. If you make code changes, remember that Octane needs to restart to pick them up, or you can use the `--watch` flag during development.
Pest Stressless
Products
Jan 2024 • 1 videos
High activity month for Pest Stressless. Laravel among the most active voices, with 1 videos across 1 sources.
Jan 2024
- Jan 12, 2024