Laravel Octane is here

  • install a new Laravel application from scratch;
  • install Laravel Octane;
  • install Roadrunner Application Server;
  • launch Laravel Octane;
  • install a HTTP Benchmarking tool.

Install and Setup your Application

composer global require laravel/installer
laravel new laravel-octane
cd laravel-octane
composer require laravel/octane
php artisan octane:install
composer require spiral/roadrunner
./vendor/bin/rr get-binary
chmod u+x rr
php artisan octane:start
php artisan octane:start --port=8002
php artisan octane:start --port=8002 --workers=8

Execute test comparison, Nginx VS Roadrunner

brew install wrk
  • 4 threads to use;
  • 20 connections to keep open;
  • 10 secondo of duration of test.
wrk -t4 -c20 -d10s http://laravel-octane.test
wrk -t4 -c20 -d10s http://laravel-octane.test:8000
Launch wrk on Nginx
Launch wrk on Laravel Octane

Some considerations

  • The Application is bootstrapped once, and multiple request will share same resources;
  • The construct of the controller are called once (when the worker is instanced);
  • Think about what happens to “static” class attribute.
use App\Http\Controllers\MainController;
Route::get('/', [MainController::class, 'index']);
Route::get('/show', [MainController::class, 'show']);
  • define a static attribute (array) $list;
  • define index method where you append a random integer to the self::$list array;
  • define show method where you use and show the self::$list array
<?php// app/Http/Controllers/MainController.phpnamespace App\Http\Controllers;
use Illuminate\Http\Request;
class MainController extends Controller{
public static $list = [];
public function index() {
self::$list[]= \random_int(1,6);
return view('welcome');
}
public function show() {
return view('show', ["list" => self::$list]);
}
}
{{-- resources/views/show.blade.php --}}<h2>LIST:</h2><p>{{ implode(",",$list) }}</p><p>DONE</p>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store