RoadRunner PSR-7 is a high performance server with an implementation of the Go language, you're not wrong, is the Go language.
Go RoadRunner first used to achieve a high-performance server, and then forwards the request to the plurality of through goridge IPC PHP CLI Worker, Worker will request re-packaged into PSR-7 Request frame to be processed.
Entertainment test
Siege test using Laravel Welcome page 250 concurrent users, for 30 seconds, and Comparative Nginx + FPM RoadRunner.
Nginx + FPM:
$ siege --no-parser -c 250 -t 30s http://127.0.0.1:3000/ > /dev/null
** SIEGE 4.0.4
** Preparing 250 concurrent users for battle.
The server is now under siege...
Lifting the server siege...
Transactions: 2032 hits
Availability: 97.83 %
Elapsed time: 29.19 secs
Data transferred: 4.51 MB
Response time: 2.64 secs
Transaction rate: 69.61 trans/sec
Throughput: 0.15 MB/sec
Concurrency: 183.50
Successful transactions: 2032
Failed transactions: 45
Longest transaction: 27.34
Shortest transaction: 0.
RoadRunner(4 worker):
$ siege --no-parser -c 250 -t 30s http://127.0.0.1:8080/ > /dev/null
** SIEGE 4.0.4
** Preparing 250 concurrent users for battle.
The server is now under siege...
Lifting the server siege...
Transactions: 61417 hits
Availability: 100.00 %
Elapsed time: 29.26 secs
Data transferred: 135.95 MB
Response time: 0.12 secs
Transaction rate: 2099.01 trans/sec
Throughput: 4.65 MB/sec
Concurrency: 249.06
Successful transactions: 61417
Failed transactions: 0
Longest transaction: 0.20
Shortest transaction: 0.05
How to speed up Laravel application
RoadRunner installation
RoadRunner has provided pre-compiled executable file, you can download the corresponding version of the platform, configuration files are available RoadRunner provides: Using RoadRunner.
Laravel configuration
Installation depends:
composer require spiral/roadrunner zendframework/zend-diactoros symfony/psr-http-message-bridge
Create a psr-worker.php in Laravel project, code changes from tobias-kuendig:
<?php
require __DIR__ . "/vendor/autoload.php";
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
$relay = new Spiral\Goridge\StreamRelay(STDIN, STDOUT);
$psr7 = new Spiral\RoadRunner\PSR7Client(new Spiral\RoadRunner\Worker($relay));
$app = require_once __DIR__ . '/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
while ($req = $psr7->acceptRequest()) {
try {
$httpFoundationFactory = new HttpFoundationFactory();
if (strpos($req->getHeaderLine("content-type"), "application/json") === 0) {
$body = $req->getBody();
$parsedBody = json_decode($body, true);
$req = $req->withParsedBody($parsedBody);
}
$symfonyReq = $httpFoundationFactory->createRequest($req);
$request = Illuminate\Http\Request::createFromBase($symfonyReq);
$response = $kernel->handle($request);
$psr7factory = new DiactorosFactory();
$psr7response = $psr7factory->createResponse($response);
$psr7->respond($psr7response);
} catch (\Throwable $e) {
$psr7->getWorker()->error((string)$e);
}
}
Run rr serve -v get.
Learn more information, please visit:
Above hope to help everyone, many PHPer always encounter some problems and bottlenecks in the advanced time, write more business code no sense of direction, I do not know from where to start to ascend, which I compiled some information, including but not limited to: a distributed architecture, highly scalable, high-performance, high-concurrency, server performance tuning, TP6, laravel, YII2, Redis , Swoole, Swoft, Kafka, Mysql optimization, shell scripts, Docker, micro-services, Nginx, etc. more advanced knowledge required for advanced dry goods can be free for everyone to share , need to be added to my official group here .