Utilize Octane to increase the running speed of Fresns by more than tenfold
Laravel Octane supercharges your application's performance by serving your application using high-powered application servers, including FrankenPHP, Open Swoole, Swoole, and RoadRunner. Octane boots your application once, keeps it in memory, and then feeds it requests at supersonic speeds.
By employing the #Octane solution, you can boost Fresns’ speed by over tenfold. Below is the process for enabling it.
Installation and activation must be performed in the terminal, starting by navigating to the Fresns root directory.
Installation of Octane
composer require laravel/octane
Installation of Services
Octane supports four acceleration services:
For example, to install the #FrankenPHP service:
php artisan octane:install --server=frankenphp
Activation of Service
php artisan octane:start
The octane:start
command can take the following options:
-
--host
: The IP address the server should bind to (default:127.0.0.1
) -
--port
: The port the server should be available on (default:8000
) -
--admin-port
: The port the admin server should be available on (default:2019
) -
--workers
: The number of workers that should be available to handle requests (default:auto
) -
--max-requests
: The number of requests to process before reloading the server (default:500
) -
--caddyfile
: The path to the FrankenPHPCaddyfile
file -
--https
: Enable HTTPS, HTTP/2, and HTTP/3, and automatically generate and renew certificates -
--http-redirect
: Enable HTTP to HTTPS redirection (only enabled if –https is passed) -
--watch
: Automatically reload the server when the application is modified -
--poll
: Use file system polling while watching in order to watch files over a network -
--log-level
: Log messages at or above the specified log level
To ensure the service remains active, it should be added to process monitoring, similar to queue configuration
Utilizing the Service
- When Octane is enabled, direct site requests to the Octane service.
- For example, with Nginx, modify the
URL Rewriting
rules to the following configuration:
location /index.php {
try_files /not_exists @octane;
}
location / {
try_files $uri $uri/ @octane;
}
location @octane {
set $suffix "";
if ($uri = /index.php) {
set $suffix ?$query_string;
}
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://127.0.0.1:8000$suffix;
}
Configuration Overview
Enforcing HTTPS
Add a line in the .env
file in the root directory: OCTANE_HTTPS=true
Configuring Maximum Execution Time
The default maximum execution time is 30 seconds:
- Modify the
config/octane.php
file -
max_execution_time
You may set this value to 0 to indicate that there isn't a specific time limit on Octane request execution time.
Configuring File Monitoring
With monitoring enabled, the service automatically restarts when files are modified.
# Activation command
php artisan octane:start --watch
- Install the Node file monitoring library first
npm install --save-dev chokidar
- If the npm command is not installed, install npm first
- Example command to install npm on Debian/Ubuntu
sudo apt install -y nodejs
- Additionally, modify the
config/octane.php
file- Add plugins and themes to the
watch
array in the configuration file to monitor changes toplugins
andthemes
files. - See configuration examples in the screenshot.
- Add plugins and themes to the