小編給大家分享一下怎么用RoadRunner加速Laravel應(yīng)用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
成都創(chuàng)新互聯(lián)公司長(zhǎng)期為超過(guò)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為吳興企業(yè)提供專(zhuān)業(yè)的做網(wǎng)站、網(wǎng)站建設(shè),吳興網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。RoadRunner是一個(gè)用Go語(yǔ)言實(shí)現(xiàn)的高性能PSR-7服務(wù)器,你沒(méi)看錯(cuò),是Go語(yǔ)言實(shí)現(xiàn)的。
RoadRunner首先用Go實(shí)現(xiàn)了一個(gè)高性能的服務(wù)器,然后通過(guò)goridge IPC把請(qǐng)求轉(zhuǎn)發(fā)給多個(gè)PHP CLI Worker,Worker會(huì)把請(qǐng)求重新封裝成PSR-7 Request交給框架進(jìn)行處理。
推薦:laravel教程
娛樂(lè)測(cè)試
使用siege測(cè)試Laravel的Welcome頁(yè)面,250個(gè)并發(fā)用戶,持續(xù)30秒,對(duì)比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
如何加速Laravel應(yīng)用
RoadRunner安裝
RoadRunner已經(jīng)提供了預(yù)編譯的執(zhí)行文件,下載對(duì)應(yīng)平臺(tái)的版本即可,配置文件可用RoadRunner提供的:Using RoadRunner.
Laravel配置
安裝依賴(lài):
composer require spiral/roadrunner zendframework/zend-diactoros symfony/psr-http-message-bridge
在Laravel項(xiàng)目創(chuàng)建一個(gè)psr-worker.php,代碼修改來(lái)自tobias-kuendig:
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); } }
運(yùn)行rr serve -v搞定。
以上是“怎么用RoadRunner加速Laravel應(yīng)用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!