欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > php常用开发框架性能对比

php常用开发框架性能对比

2025/2/22 16:54:58 来源:https://blog.csdn.net/weixin_45476104/article/details/144943198  浏览:    关键词:php常用开发框架性能对比

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、框架简介?
    • 1.1 webman
    • 1.2 CodeIgniter(CI框架)
    • 1.3 ThinkPHP
    • 1.4 Laravel
    • 1.5 EasySwoole
  • 二、压测对比
    • 1.机器配置
    • 2.webman压测
    • 2. ThinkPHP压测
    • 3. Laravel压测
    • 4. CodeIgniter压测
    • 5. EasySwoole压测
  • 三、 压测数据汇总
  • 四 、框架优缺点对比
    • 4.1 Webman
    • 4.2 CodeIgniter
    • 4.3 ThinkPHP
    • 4.4 Laravel
    • 4.5 EasySwoole
  • 总结


前言

本文将简单介绍一下常用框架,webman,CodeIgniter,ThinkPHP,laravel框架,通过ab压力测试,对比一下性能,从ab压测参数,占用内存等方面简单对比一下


以下内容仅供参考

一、框架简介?

1.1 webman

webman是一款基于workerman开发的高性能HTTP服务框架。webman用于替代传统的php-fpm架构,提供超高性能可扩展的HTTP服务。你可以用webman开发网站,也可以开发HTTP接口或者微服务。

学习手册:webman手册

1.2 CodeIgniter(CI框架)

CodeIgniter 是一个功能强大的 PHP 框架,占用空间非常小,专为需要简单而优雅的工具包来创建功能齐全的 Web 应用程序的开发人员而构建.

学习手册: CodeIgniter手册

1.3 ThinkPHP

ThinkPHP是一个免费开源的,快速、简单的面向对象的轻量级PHP开发框架,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性
学习手册: ThinkPHP手册

1.4 Laravel

一个渐进式框架 ,可扩展的框架 ,Laravel 结合了 PHP 生态系统中最好的包,提供了最健壮和对开发者最友好的框架。
学习手册:Laravel

1.5 EasySwoole

EasySwoole 是一款基于 Swoole Server 开发的常驻内存型的分布式 PHP 框架,专为 API 而生,摆脱传统 PHP 运行模式在进程唤起和文件加载上带来的性能损失。 EasySwoole 高度封装了 Swoole Server 而依旧维持 Swoole Server 原有特性,支持同时混合监听 HTTP、自定义 TCP、UDP 协议,让开发者以最低的学习成本和精力编写出多进程、可异步、高可用的应用服务
学习手册: EasySwoole学习手册

二、压测对比

1.机器配置

本文压测使用的是虚拟机,配置如下
虚拟配置虚拟机系统版本信息

[root@slave_1 webman]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[root@slave_1 webman]#

php版本信息如下

[root@slave_1 webdata]# 
[root@slave_1 webdata]# php -v
PHP 7.4.33 (cli) (built: Dec  8 2024 23:43:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

2.webman压测

webman启动后进程信息(如下):

[root@slave_1 webman]# 
[root@slave_1 webman]# php start.php  start
Workerman[start.php] start in DEBUG mode
-------------------------------------------- WORKERMAN --------------------------------------------
Workerman version:4.1.17          PHP version:7.4.33           Event-Loop:\Workerman\Events\Select
--------------------------------------------- WORKERS ---------------------------------------------
proto   user            worker          listen                 processes    status           
tcp     root            webman          http://0.0.0.0:8787    4             [OK]            
tcp     root            monitor         none                   1             [OK]            
---------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
/data/webdata/webman/config/process.php updated and reload
Workerman[start.php] reloading# webman接口逻辑,只是简单返回json数据接口
[root@master /]# curl slave_1:8787/index/getBannerList
{"code":200,"msg":"ok","data":{"list":{"name":"ab压力测试webman","img_url":""}}}[root@master /]#

webman压测数据

[root@master /]# ab -c 500 -n 10000 -k  slave_1:8787/index/getBannerList
Server Software:        workerman
Server Hostname:        slave_1
Server Port:            8787Document Path:          /index/getBannerList
Document Length:        84 bytesConcurrency Level:      500
Time taken for tests:   0.708 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    10000
Total transferred:      1980000 bytes
HTML transferred:       840000 bytes
Requests per second:    14133.36 [#/sec] (mean)
Time per request:       35.377 [ms] (mean)
Time per request:       0.071 [ms] (mean, across all concurrent requests)
Transfer rate:          2732.82 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    3  12.7      0      71
Processing:     2   30  14.2     28      95
Waiting:        1   30  14.2     28      95
Total:          2   33  19.2     29     111Percentage of the requests served within a certain time (ms)50%     2966%     3275%     3680%     4190%     6295%     7198%     9499%    100100%    111 (longest request)
[root@master /]# 
# webman占用程序占用内存 2231520/1024/1024 =2.12M
[root@slave_1 conf]# curl 127.0.0.1:8787/index/getBannerList
{"code":200,"msg":"ok","data":{"list":{"name":"ab压力测试webman","img_url":"","$memoryUsage":2231520}}}

在这里插入图片描述

2. ThinkPHP压测

压测参数

# 本例使用的ThinkPHP版本信息 5.1
[root@master /]# ab -c 100 -n 1000 -k  http://192.168.40.130:8081/index.php/index/index
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Server Software:        openresty/1.27.1.1
Server Hostname:        192.168.40.130
Server Port:            8081Document Path:          /index.php/index/index
Document Length:        102 bytesConcurrency Level:      100
Time taken for tests:   13.576 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      278000 bytes
HTML transferred:       102000 bytes
Requests per second:    73.66 [#/sec] (mean)
Time per request:       1357.620 [ms] (mean)
Time per request:       13.576 [ms] (mean, across all concurrent requests)
Transfer rate:          20.00 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    6   7.1      4      94
Processing:    21 1288 241.7   1351    1644
Waiting:        9 1287 241.7   1351    1637
Total:         26 1294 240.2   1358    1646Percentage of the requests served within a certain time (ms)50%   135866%   137875%   138980%   139690%   141595%   143198%   144999%   1499100%   1646 (longest request)# php-fpm 占用内存大小 [root@slave_1 server]# ps -axu | grep php-fpm
root        984  0.0  0.5 220476 10040 ?        Ss   1月04   0:11 php-fpm: master process (/soft/php_7_4_33/etc/php-fpm.conf)
www-data   9347 24.7  0.5 222740 10268 ?        R    19:19   0:15 php-fpm: pool www
www-data   9350 20.6  0.5 222740 10260 ?        R    19:19   0:08 php-fpm: pool www
www-data   9351 20.5  0.5 222740 10264 ?        R    19:19   0:08 php-fpm: pool www
www-data   9352 43.8  0.5 222740 10260 ?        R    19:20   0:03 php-fpm: pool www
www-data   9353 36.5  0.5 222740 10268 ?        R    19:20   0:02 php-fpm: pool www# 程序占用内存大小2332224/1024/1024 =2.2 M[root@slave_1 server]# curl 127.0.0.1:8081/index.php/index/index
{"code":200,"msg":"ok","data":{"list":{"name":"ab压力测试Tp","img_url":""}},"memoryUsage":2332224}

在这里插入图片描述

3. Laravel压测

本次压测使用和ThinkPHP一致的压测参数

# 本例使用的laravel版本为 8.75
[root@master /]# ab -c 100 -n 1000 -k  http://192.168.40.130:8082/index.php/api/test
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Server Software:        openresty/1.27.1.1
Server Hostname:        192.168.40.130
Server Port:            8082Document Path:          /index.php/api/test
Document Length:        109 bytesConcurrency Level:      100
Time taken for tests:   81.520 seconds
Complete requests:      1000
Failed requests:        879(Connect: 0, Receive: 0, Length: 879, Exceptions: 0)
Write errors:           0
Non-2xx responses:      879
Keep-Alive requests:    0
Total transferred:      6207779 bytes
HTML transferred:       5836564 bytes
Requests per second:    12.27 [#/sec] (mean)
Time per request:       8152.002 [ms] (mean)
Time per request:       81.520 [ms] (mean, across all concurrent requests)
Transfer rate:          74.37 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    7   8.5      4     100
Processing:   185 7739 1390.8   8069    8764
Waiting:      185 7737 1390.5   8065    8764
Total:        223 7745 1387.0   8072    8772Percentage of the requests served within a certain time (ms)50%   807266%   817675%   825380%   829690%   841895%   852398%   861499%   8661100%   8772 (longest request)
# php-fpm信息
[root@slave_1 server]# ps -axu | grep php-fpm
root        984  0.0  0.5 220476 10040 ?        Ss   1月04   0:12 php-fpm: master process (/soft/php_7_4_33/etc/php-fpm.conf)
www-data   9442  0.8  1.2 235528 23620 ?        R    19:47   0:53 php-fpm: pool www
www-data  10061 21.2  1.2 235284 23268 ?        R    21:23   0:47 php-fpm: pool www
www-data  10062 19.9  1.2 235284 23308 ?        R    21:23   0:43 php-fpm: pool www
www-data  10077 40.2  1.2 235284 23268 ?        R    21:27   0:13 php-fpm: pool www
www-data  10078 38.3  1.2 235284 23272 ?        R    21:27   0:12 php-fpm: pool www
# 接口占用内存大小  14337504/1024/1024 = 13.67M
[root@master /]# curl http://192.168.40.130:8082/index.php/api/test
{"code":200,"msg":"ok","data":{"list":{"name":"ab压力测试laravel","img_url":"","$memoryUsage":14337504}}}

laravel压测

4. CodeIgniter压测

# 本例使用的CodeIgniter版本为3
[root@master ~]# ab -c 100 -n 1000 -k http://192.168.40.130:8083/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Server Software:        openresty/1.27.1.1
Server Hostname:        192.168.40.130
Server Port:            8083Document Path:          /
Document Length:        109 bytesConcurrency Level:      100
Time taken for tests:   6.985 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      278000 bytes
HTML transferred:       109000 bytes
Requests per second:    143.17 [#/sec] (mean)
Time per request:       698.476 [ms] (mean)
Time per request:       6.985 [ms] (mean, across all concurrent requests)
Transfer rate:          38.87 [Kbytes/sec] received
Percentage of the requests served within a certain time (ms)50%    73866%    75475%    76080%    76490%    77495%    78298%    79399%    798100%    834 (longest request)# php-fpm占用内存大小[root@slave_1 server]# ps -aux | grep php-fpm 
root        987  0.0  0.5 220476 10028 ?        Ss   1月05   0:01 php-fpm: master process (/soft/php_7_4_33/etc/php-fpm.conf)
www-data   1044  0.0  0.4 220540  7932 ?        R    1月05   0:02 php-fpm: pool www
www-data   1045  0.0  0.4 220540  7952 ?        R    1月05   0:03 php-fpm: pool www
www-data   1860 36.1  0.4 220540  7688 ?        R    00:29   0:02 php-fpm: pool www
www-data   1861 34.4  0.4 220540  7688 ?        R    00:29   0:01 php-fpm: pool www
www-data   1862 27.5  0.4 220540  7688 ?        R    00:29   0:01 php-fpm: pool www
# 框架代码占用内存大小 1192928/1024/1024 =1.14M
[root@master ~]# curl http://192.168.40.130:8083/
{"code":200,"msg":"ok","data":{"list":{"name":"ab压力测试CI框架","img_url":"","$memoryUsage":1192928}}}

CI框架运行

5. EasySwoole压测

# 压测参数 
#本例使用的swoole版本是 swoole version 4.8.0
#使用的EaSwoole版本是 3.5.1
[root@master ~]# ab -c 500 -n 10000 -k  http://192.168.40.130:9501/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Server Software:        EasySwoole
Server Hostname:        192.168.40.130
Server Port:            9501
Document Path:          /
Document Length:        105 bytes
Concurrency Level:      500
Time taken for tests:   0.666 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    10000
Total transferred:      2510000 bytes
HTML transferred:       1050000 bytes
Requests per second:    15004.04 [#/sec] (mean)
Time per request:       33.324 [ms] (mean)
Time per request:       0.067 [ms] (mean, across all concurrent requests)
Transfer rate:          3677.75 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    1   4.9      0      25
Processing:     2   29  15.6     25      85
Waiting:        1   29  15.6     25      85
Total:          2   30  16.3     26      85Percentage of the requests served within a certain time (ms)50%     2666%     3475%     4080%     4490%     5595%     6598%     7099%     73100%     85 (longest request)# EasySwoole相关进程占用内存大小[root@slave_1 easySwoole]# ps -axu | grep EasySwoole 
root       1537  0.1  0.8 400924 16288 pts/0    Sl+  22:30   0:00 EasySwoole
root       1538  0.0  0.4 254616  8812 pts/0    S+   22:30   0:00 EasySwoole.Manager
root       1539  0.0  0.5 258900  9348 pts/0    S+   22:30   0:00 EasySwoole.Worker.0
root       1540  0.0  0.5 258900  9352 pts/0    S+   22:30   0:00 EasySwoole.Worker.1
root       1541  0.0  0.5 258900  9348 pts/0    S+   22:30   0:00 EasySwoole.Worker.2
root       1542  0.0  0.5 258900  9348 pts/0    S+   22:30   0:00 EasySwoole.Worker.3
root       1543  0.0  0.5 258900  9348 pts/0    S+   22:30   0:00 EasySwoole.Worker.4
root       1544  0.0  0.5 258900  9348 pts/0    S+   22:30   0:00 EasySwoole.Worker.5
root       1545  0.0  0.5 258900  9348 pts/0    S+   22:30   0:00 EasySwoole.Worker.6
root       1546  0.0  0.5 258900  9348 pts/0    S+   22:30   0:00 EasySwoole.Worker.7
root       1547  0.0  0.5 260952  9572 pts/0    S+   22:30   0:00 EasySwoole.TaskWorker.0
root       1548  0.0  0.5 260952  9568 pts/0    S+   22:30   0:00 EasySwoole.TaskWorker.1
root       1551  0.0  0.5 260952  9572 pts/0    S+   22:30   0:00 EasySwoole.TaskWorker.2
root       1552  0.0  0.5 260952  9568 pts/0    S+   22:30   0:00 EasySwoole.TaskWorker.3
root       1553  0.0  0.5 260952  9560 pts/0    S+   22:30   0:00 EasySwoole.Bridge
# EasySwoole代码占用内存 4160392/1024/1024 = 3.97M
[root@master ~]# curl   http://192.168.40.130:9501/
{"code":200,"msg":"ok","data":{"list":{"name":"ab:easySwoole:test","img_url":"","$memoryUsage":4160392}}}

压测时的cpu

三、 压测数据汇总

框架QPS接口响应时间框架占用内存大小压测参数服务器RES内存大小
webman14133111 ms2.12 Mab -c 500 -n 10000 -k9.2 M
CodeIgniter(CI框架)143111 ms1.14 Mab -c 100 -n 1000 -k7.5 M
ThinkPHP731646 ms2.2 Mab -c 100 -n 1000 -k10 M
Laravel128772 ms13.67 Mab -c 100 -n 1000 -k22.8 M
EasySwoole1500485 ms3.97 Mab -c 500 -n 10000 -k9.1 M

四 、框架优缺点对比

4.1 Webman

优点: 高性能,轻量级,灵活部署,学习成本低,易于集成和扩展
缺点: 生态相对较小,不适合大型复杂项目

4.2 CodeIgniter

优点: 简单易用,快速开发,资源占用少,轻量级且高效,良好的兼容性
缺点:功能相对有限,学习资料相对较少,不是很适合现代大型应用开发

4.3 ThinkPHP

优点: 功能丰富强大,易于上手,社区活跃,易于上手,支持多种开发模式
缺点: 性能方面有提升空间,框架较复杂

4.4 Laravel

优点: 优雅的语法和设计模式,强大的生态系统,内置功能丰富,活跃的社区支持
缺点: 学习成本较高,性能在某些场景下受影响,部署相对复杂,资源占用较多

4.5 EasySwoole

优点: 高性能异步处理,多协议支持,适合开发微服务和分布式应用,功能全面,可扩展性强,适用于对稳定性要求较高的生产环境

缺点: 学习难度较大,生态相对较小,代码调试相对困难,对 PHP 版本和 Swoole 扩展有要求,不适合传统 PHP 开发模式


总结

以上就是今天要讲的内容,本文仅简单介绍每种框架 使用相同的参数,在相同的虚拟机环境下进行压测,粗略预估下一下各框架的性能,在实际开发过程中,应充分考虑到,各框架学习成本,开发人员的技术储备,成本维护,以及框架社区活跃度,技术资料是否丰富,以及项目复杂度等等,综合考虑,来决定选择哪种框架。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词