Are you doubting the potential performance of the PHP application you’ve been building with Laravel Framework? As an interpreted language, PHP is slow. Factor in the apparent out-of-the-box slowness that we could attribute to the framework; your application could be slower. Also, PHP JIT and Opcache may not be enough. If you’ve heard about Laravel Octane, it enables us to serve our Laravel application using high-powered application servers. This post shows how to serve a Laravel application using Roadrunner on a local machine.
Laravel Application plus Roadrunner on a local machine
To emphasize the limitation of such a setup, this post ONLY shows the use of a development environment on a local machine. Any attempt to replicate it in a production setup will require more than this post offers.
We will use Laravel 9, Windows 10, Composer, PHP 8, and Roadrunner.
Roadrunner and a Laravel Application To Use
First, we need a Laravel application. It could be a new or an existing application that we can run locally via the artisan command. Next, we install Laravel Octane using the following command.
1 | composer require laravel/octane |
Among other things, this command creates script files in the vendor\bin folder. These include the following.
- roadrunner-worker
- roadrunner-worker.bat
- swoole-server
- swoole-server.bat
We will reference one of these files in a roadrunner configuration file (.yaml).
Then, we run another command to install support for the roadrunner and serve the Laravel application using roadrunner.
1 | composer require spiral/roadrunner |
Next, we download roadrunner.
Then, go to the releases section and download the correct binary files. For this post, we use binaries for Windows.
Next, unzip the file and copy the file rr.exe to the root folder of a Laravel project.
Roadrunner .rr.yaml Configuration File
Next, we create a .rr.yaml file for roadrunner and place it in the same folder as the file rr.exe. Notice that we may need to change the APP_BASED_PATH to point to the Laravel root folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | http: address: 127.0.0.1:8000 pool: num_workers: 0 max_jobs: 500 supervisor: exec_ttl: 30s static: dir: public middleware: [ "static" ] server: command: "php ./vendor/bin/roadrunner-worker" env: - APP_ENV: production - APP_BASE_PATH: "C:/Users/karl/OneDrive/Desktop/roadrunner-target" - LARAVEL_OCTANE: "1" - DB_CONNECTION: mysql - DB_HOST: 127.0.0.1 - DB_PORT: 3306 - DB_DATABASE: laravelappdb - DB_USERNAME: laravelapp - DB_PASSWORD: 7fe6e484-507e-4226-960b-08c8888a59ad rpc: listen: tcp://127.0.0.1:6001 logs: mode: production level: debug output: stdout encoding: json |
Startup Roadrunner
Finally, we can start roadrunner and serve the Laravel application using the command rr serve.