当前位置: 代码网 > 服务器>服务器>Linux > 关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解

关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解

2025年03月30日 Linux 我要评论
目前我安装的 homestead 虚拟机版本是 2.1.8:该版本 homestead 上预装的 php 版本是 5.6.15:我们使用 ab 命令(apache 提供的性能测试工具)在该版本中测试

目前我安装的 homestead 虚拟机版本是 2.1.8:

04f5e4cf07c786c46f917d4f9ae59db.png

该版本 homestead 上预装的 php 版本是 5.6.15:

812502c82d975ab1678cfd51f11b314.png

我们使用 ab 命令(apache 提供的性能测试工具)在该版本中测试 laravel 应用(以目前正在讲的使用laravel开发的博客应用为例)性能,我们模拟 10000 次请求,100 个并发进行压力测试:

ab -n 10000 -c 100 http://blog.app/
登录后复制
登录后复制

运行结果如下:

this is apachebench, version 2.3 
copyright 1996 adam twiss, zeus technology ltd, http://www.zeustech.net/
licensed to the apache software foundation, http://www.apache.org/

benchmarking blog.app (be patient)
completed 1000 requests
completed 2000 requests
completed 3000 requests
completed 4000 requests
completed 5000 requests
completed 6000 requests
completed 7000 requests
completed 8000 requests
completed 9000 requests
completed 10000 requests
finished 10000 requests
server software: nginx/1.8.0
server hostname: blog.app
server port: 80

document path: /
document length: 324 bytes

concurrency level: 100
time taken for tests: 69.354 seconds
complete requests: 10000
failed requests: 0
total transferred: 19851388 bytes
html transferred: 10230000 bytes
requests per second: 144.19 [#/sec] (mean)
time per request: 693.545 [ms] (mean)
time per request: 6.935 [ms] (mean, across all concurrent requests)
transfer rate: 279.52 [kbytes/sec] received

connection times (ms)
                  min  mean[+/-sd]  median  max
connect:       0       0     0.2                 0      3
processing: 17    684   319.1           588   2720
waiting:      17     684   319.1           588   2720
total:          20     684   319.1           588   2720

percentage of the requests served within a certain time (ms)
 50%      588
 66%      695
 75%      842
 80%      933
 90%    1155
 95%    1321
 98%    1545
 99%    1813
 100%  2720 (longest request)
登录后复制

这里我们要关注的是红色加粗的文字,即每秒处理请求数,这是衡量系统性能的关键指标。根据系统及硬件配置的差异,数据会有些出入。

现在我们按照“laravel homestead 支持 php 7 ”这一节所述将 homestead 中的 php 升级到 7.0 版本。

使用 vagrant ssh 登录到新添加的 homestead-7 虚拟机,查看 php 版本信息是否正确:

756b5cb7d22352cdbd3701f38333ee4.png

此时在浏览器中访问 http://blog.app 会报错,因为新安装的 homestead 数据库数据为空,需要登录到虚拟机运行如下命令运行迁移并填充数据:

php artisan migrate 
php artisan db:seed
登录后复制

再次访问就ok了,好了我们继续使用同样的 ab 命令进行压力测试:

ab -n 10000 -c 100 http://blog.app/
登录后复制
登录后复制

运行结果如下:

this is apachebench, version 2.3 
copyright 1996 adam twiss, zeus technology ltd, http://www.zeustech.net/
licensed to the apache software foundation, http://www.apache.org/

benchmarking blog.app (be patient)
completed 1000 requests
completed 2000 requests
completed 3000 requests
completed 4000 requests
completed 5000 requests
completed 6000 requests
completed 7000 requests
completed 8000 requests
completed 9000 requests
completed 10000 requests
finished 10000 requests
server software: nginx/1.8.0
server hostname: blog.app
server port: 80

document path: /
document length: 324 bytes

concurrency level: 100
time taken for tests: 45.032 seconds
complete requests: 10000
failed requests: 0
total transferred: 20101202 bytes
html transferred: 10230000 bytes
requests per second: 222.06 [#/sec] (mean)
time per request: 450.319 [ms] (mean)
time per request: 4.503 [ms] (mean, across all concurrent requests)
transfer rate: 435.91 [kbytes/sec] received

connection times (ms)
                  min  mean[+/-sd]  median   max
connect:       0       0     0.2                 0       4
processing: 11    443   252.8           379   1978
waiting:      11     443   252.8           379   1978
total:          15     443   252.8           379   1978

percentage of the requests served within a certain time (ms)
 50%      379
 66%      517
 75%      590
 80%      631
 90%      795
 95%      938
 98%    1060
 99%    1229
 100%  1978 (longest request)
登录后复制

经过对比,同一个 laravel 应用在 php 7.0 下的性能比 php 5.6 提高了54%,这是一个很显著的性能提升,当然环境不同数据会有所出入,而且还有更大的提升空间。

原文地址:https://xueyuanjun.com/post/2398

以上就是关于php7.0与php5.6下laravel博客应用性能对比分析详解的详细内容,更多请关注代码网其它相关文章!

(0)

相关文章:

  • 12306抢票,极限并发带来的思考!

    12306抢票,极限并发带来的思考?每到节假日期间,一二线城市返乡、外出游玩的人们几乎都面临着一个问题:抢火车票!虽然现在大多数情况下都能订到票,但是放票瞬间即无票的场景,相信大家…

    2025年03月30日 服务器
  • php如何实现多线程

    php如何实现多线程

    php中可以实现多线程,是一种利用旧的exec函数通过异步处理方法实现多线程的,exec函数本身就是一个执行外部程序的php函数。下面我们就来具体看看php多线... [阅读全文]
  • tidb是go语言么

    tidb是go语言么

    是,tidb采用go语言编写。tidb是一个分布式newsql数据库;它支持水平弹性扩展、acid事务、标准sql、mysql语法和mysql协议,具有数据强一... [阅读全文]
  • Homestead安装php Redis扩展的步骤及遇到的问题解决

    Homestead安装php Redis扩展的步骤及遇到的问题解决

    本篇文章给大家带来的内容是关于homestead安装php redis扩展的步骤及遇到的问题解决,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。... [阅读全文]
  • mysql router是什么

    mysql router是mysql官方提供的一个轻量级中间件,是innodb cluster的一部分,可在应用程序和后端mysql服务器之间提供透明路由;它主要用以解决mysql…

    2025年03月30日 服务器
  • Laravel本地环境搭建:Homestead开发环境的部署

    Laravel本地环境搭建:Homestead开发环境的部署

    laravel框架在php开发过程是不断进行优化的,当然也包括了本地环境的开发,下面我们就来具体看看laravel框架中的homestead 开发环境的部署内容... [阅读全文]

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com