RoadRunner是一个用Go语言实现的高性能psr-7服务器,你没看错,是Go语言实现的。
RoadRunner首先用Go实现了一个高性能的服务器,然后通过gorIDge IPC把请求转发给多个PHP Cli Worker,Worker会把请求重新封装成psr-7 Request交给框架进行处理。
推荐:laravel教程
娱乐测试
使用sIEge测试Laravel的Welcome页面,250个并发用户,持续30秒,对比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 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 250 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
如何加速Laravel应用
RoadRunner安装
RoadRunner已经提供了预编译的执行文件,下载对应平台的版本即可,配置文件可用RoadRunner提供的:Using RoadRunner.
Laravel配置
安装依赖:
composer require spiral/roadrunner Zendframework/Zend-diactoros symfony/psr-http-message-brIDge
在Laravel项目创建一个psr-worker.PHP,代码修改来自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);$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); }}
运行rr serve -v搞定。 总结
以上是内存溢出为你收集整理的如何用RoadRunner加速Laravel应用全部内容,希望文章能够帮你解决如何用RoadRunner加速Laravel应用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)