In the PHP area these days, there are a few HTTP servers or application servers for PHP that have different execution methods from the conventional configuration by common Apache + mod_php and PHP-FPM, as represented by Swoole. It is getting more and more attention.
RoadRunner
RoadRunner is one such emerging application server, written in Go language. The HTTP request is handled by Go's HTTP handler in the previous stage, and the load balancer/process manager allocates the request to the PHP Worker.
In addition to the regular HTTP server, the implementation of gRPC server by RoadRunner is also open to the public, showing new possibilities for PHP.
RoadRunner also supports Laravel, and packages for Laravel have also been developed.
This time, I would like to implement RoadRunner based on this.
First, install the package with the following command.
# roadrunner
composer require spiral/roadrunner "^1.8"
# roadrunner-laravel
composer require spiral/roadrunner-laravel "^3.4"
Next, execute the following command to create a package configuration file (./config/roadrunner.php).
php artisan vendor:publish --provider='Spiral\RoadRunnerLaravel\ServiceProvider' --tag=config
Write a roadrunner configuration yml file.
Set to start on port 80.
env:
APP_REFRESH: true
http:
address: 0.0.0.0:80
http2:
enabled: true
h2c: true
maxConcurrentStreams: 128
workers:
command: 'php ./vendor/bin/rr-worker'
static:
dir: public
reload:
interval: 1s
patterns: [ '.php' ]
services:
http:
dirs: [ '' ]
recursive: true
logging.php
'stdout' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'with' => [
//php://If you set it to stdout, an error will occur and it will be moss, so php://Change to stderr
'stream' => 'php://stderr',
],
'level' => 'debug',
],
Add script to composer.json.
"scripts": {
"roadrunner:dev": [
"composer dump-autoload",
"./rr serve -v -d"
],
"roadrunner:prod": [
"./rr serve"
],
"roadrunner:setup": [
"rr get-binary"
],
}
Put the startup command in startup.sh
# roadrunner
composer roadrunner:setup
chmod +x rr
composer roadrunner:dev
This completes most of the settings.
Follow the steps below to start it.
cp docker-compose.example.yml docker-compose.yml
docker-compose up -d
I was able to start it safely.
This time, I used PHP web / application server made by Golang. I made a sample. It's interesting, but it's unstable, so I don't recommend using it in a production environment.
https://nextat.co.jp/staff/archives/235
Recommended Posts