当前位置: 首页 > Linux

LaravelOctane安装RoadRunner

时间:2023-04-06 20:21:15 Linux

在上一篇文章中,我们实现了Swoole在Laravel中的安装和使用。本文将讲解RoadRunner的安装和使用。安装RoadRunner与安装Swoole类似,唯一的区别是RoadRunner不需要安装php扩展。环境要求unix系统下必须安装PHP8.0+Larave8.35+Swoole和RoadRunner(macOS,linux,window(WSL2))RoadRunner:请确保已安装curl,zipsockets等php扩展虚拟机IP:192.168。2.11第一步。安装octane包composer需要laravel/octaneStep2。配置nginx代理映射$http_upgrade$connection_upgrade{默认升级;''关闭;}服务器{听8009;#浏览器访问的端口#listen[::]:80;服务器名称127.0.0.1;服务器令牌关闭;根/var/www/html/octane/public;索引index.php;字符集utf-8;location/index.php{try_files/not_exists@octane;}location/{try_files$uri$uri/@octane;}location=/favicon.ico{access_logoff;log_not_found关闭;}location=/robots.txt{access_logoff;log_not_found关闭;}access_log/var/log/nginx/octane-access.logmain;error_log/var/log/nginx/octane-error.log错误;error_page404/index.php;位置@octane{设置$suffix"";如果($uri=/index.php){设置$suffix?$query_string;}proxy_http_version1.1;proxy_set_header主机$http_host;proxy_set_header计划$scheme;proxy_set_headerSERVER_PORT$server_port;proxy_set_headerREMOTE_ADDR$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_header升级$http_upgrade;proxy_set_header连接$connection_upgrade;proxy_passhttp://127.0.0.1:8010$后缀;#代理请求}}proxy_pass表示http://127.0.0.1:8010代理转发来自http://192.168.2.110:8009的请求Step3。使用RoadRunner1。安装spiral/roadrunner#不同版本可能表现不同,尽量使用最新版本composerrequirespiral/roadrunner:v2.4.02。发布配置文件phpartisanoctane:installoutput:Whichapplicationserveryouwouldliketouse?:[0]roadrunner[1]swoole>0select0,表示我们选择RoadRunner3。获取二进制文件。/vendor/bin/rrget-binary4.运行phpartisanoctane:start--server=roadrunner--port=8010output:INFOServerrunning...Local:http://127.0.0.1:8010按Ctrl+C停止服务器看到这里,说明安装成功5、在浏览器中访问在浏览器中输入http://192.168.2.11:8009,回车。可以看到命令界面会出现一个GET请求。可以看出只有前两次请求耗时较长,后面的请求只有几毫秒。:8010/-n1000:指定测试会话使用的请求数为1000-c8:并发数为8,压测结果使用octane[root@localhostoctane]#ab-n1000-c8http://127.0.0.1:8010/test-mysqlThisisApacheBench,Version2.3<$Revision:1430300$>版权所有1996AdamTwiss,ZeusTechnologyLtd,http://www.zeustech.net/授权给ApacheSoftwareFoundation,http://www.apache.org/Benchmarking127.0.0.1(请耐心等待)已完成100个请求已完成200个请求已完成300个请求已完成400个请求已完成500个请求已完成700个请求已完成800个请求已完成900个请求已完成1000个请求已完成1000个请求服务器软件:服务器Portument:8010:服务器主机名:0.10.0/test-mysqlDocumentLength:0bytesConcurrencyLevel:8Timetakenfortests:22.446secondsCompleterequests:1000Failedrequests:0写入错误:0总传输量:1048000字节HTML传输量:0字节每秒请求数:44.55[#/sec](平均值)每个请求时间:179.566[ms](平均值)每个请求时间:22.446[ms](平均值,所有并发requests)Transferrate:45.60[Kbytes/sec]receivedConnectionTimes(ms)minmean[+/-sd]medianmaxConnect:000.101Processing:917843.9180360等待:917843.9180360总计:917843.9180360在一定时间内服务的请求的百分比(毫秒)50%18066%19475%21380%22190%23495%24298%25099%255100%360(longestrequest)**再看不使用octane的压力测试结果:[root@localhostoctane]#ab-n1000-c8http://127.0.0.1:8008/test-mysqlThisisApacheBench,Version2.3<$修订:1430300$>版权所有1996AdamTwiss,ZeusTechnologyLtd,http://www.zeustech.net/授权给Apache软件基金会,http://www.apache.org/Benchmarking127.0.0.1(请耐心等待)已完成100个请求已完成200个请求已完成300个请求已完成400个请求已完成500个请求已完成600个请求已完成700个请求已完成800个请求已完成900个请求已完成1000个请求已完成1请求服务器软件:nginx/1.20.1服务器主机名:127.0.0.1服务器端口:8008文档路径:/test-mysql文档长度:0字节并发级别:8测试时间:52.588秒完成请求:1000失败请求:0写入错误:0总传输:1134000字节HTML传输:0bytesRequestspersecond:19.02[#/sec](mean)Timeperrequest:420.705[ms](mean)Timeperrequest:52.588[ms](mean,acrossallconcurrentrequests)Transferrate:21.06[Kbytes/sec]]收到连接时间(毫秒)minmean[+/-sd]medianmaxConnect:000.101Processing:78419172.2396986Waiting:78419172.2396986Total:78419172.2396986在63ms特定时间内处理的请求的百分比6%5%%51056880%59190%65595%70698%74099%761100%986(最长请求)从上面两个结果可以看出,RoadRunner还可以大大提高速度