This article mainly introduces the use of Roadrunner accelerated Laravel application, has a certain reference value, now share to everyone, the need for friends can refer to
Roadrunner is a high-performance PSR-7 server implemented with Go language, you can read it correctly, it is the go language implementation.
Roadrunner first implemented a high-performance server with Go, and then forwarded the request through the Goridge IPC to multiple PHP CLI Worker,worker will re-encapsulate the request to the framework for processing PSR-7 requests.
Entertainment testing
Use siege to test Laravel's Welcome page, 250 concurrent users, for 30 seconds, compared to Nginx + FPM and Roadrunner.
Nginx + FPM:
$ siege--no-parser-c 250-t 30s http://127.0.0.1:3000/ >/dev/null** Siege 4.0.4** Preparing concurrent users For battle. The server is now under siege ... Lifting the server siege ... Transactions: 2032 hitsavailability: 97.83%elapsed time: 29.19 Secsdata transferred: 4.51 Mbresponse time: 2.64 secstransaction rate: 69.61 trans/secthroughput: 0.15 mb/secconcurrency: 183.50Successful transactions: 2032Failed transactions: 45Longest transaction: 27.34Shortest 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 concurrent users For battle. The server is now under siege ... Lifting the server siege ... Transactions: 61417 hitsavailability: 100.00%elapsed time: 29.26 Secsdata transferred: 135.95 Mbresponse time: 0.12 secstransaction Rate: 2099.01 trans/secthroughput: 4.65 mb/secconcurrency: 249.06Successful transactions: 61417Failed transactions: 0Longest transaction: 0.20Shortest Transaction: 0.05
How to speed up laravel applications
Roadrunner installation
RoadRunner has provided the precompiled execution file, download the version of the corresponding platform, the configuration file can be provided by RoadRunner: Using RoadRunner.
Laravel Configuration
Installation dependencies:
Composer require Spiral/roadrunner Zendframework/zend-diactoros Symfony/psr-http-message-bridge
In the Laravel project, create a psr-worker.php
code modification from Tobias-kuendig:
<?phprequire __dir__. "/vendor/autoload.php"; use Symfony\bridge\psrhttpmessage\factory\diactorosfactory;use Symfony\Bridge\ psrhttpmessage\factory\httpfoundationfactory; $relay = new Spiral\goridge\streamrelay (STDIN, STDOUT); $PSR 7 = 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 = $PSR 7-> 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); $PSR 7factory = new DiactorOsfactory (); $PSR 7response = $psr 7factory->createresponse ($response); $PSR 7->respond ($PSR 7response); } catch (\throwable $e) {$psr 7->getworker ()->error ((string) $e); }}
Run and get it rr serve -v
done.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!