当前位置: 首页 > 编程文章 >

MixPHP、Yii与CodeIgniter在Apache环境下的并发性能对比

MixPHP、Yii与CodeIgniter在Apache环境下的并发性能对比

作者:许知时间:2025-04-03 10:03:09浏览:342

本文对基于Swoole的MixPHP、轻量级CodeIgniter及流行框架Yii进行了并发压力测试。为公平起见,MixPHP亦部署于Apache/PHP-FPM环境。结果显示,在4核1G虚拟机中,使用ab工具进行5000次请求、100并发的压测,MixPHP达到440.48 QPS,显著高于CodeIgniter的144.42 QPS和Yii的56.40 QPS。尽管受限于虚拟机IO性能导致Yii在高并发下无响应,但同架构下MixPHP仍展现明显优势。

本文目录展开

MixPHP、Yii与CodeIgniter并发性能对比背景

前言部分简要介绍了本次对比的对象。

MixPHP是一款依托Swoole构建的高性能框架,CodeIgniter作为元老级的轻量级代表,而Yii则是目前极为流行的开发框架,三者各有特点。

鉴于Yii和CodeIgniter均基于传统的Apache或PHP-FPM架构,若直接采用MixPHP默认的Swoole部署方式进行对比并不公平。由于MixPHP同样支持在Apache/PHP-FPM环境中运行,因此本次测试将MixPHP也部署于Apache之下以确保条件一致。

测试环境配置如下。

服务器为虚拟机配置,具备4个CPU核心及1GB内存。

采用ab工具执行压力测试,具体命令参数为:ab -n 5000 -c 100 URL,即总请求数5000,并发数100。

针对Yii框架进行测试。

Yii配置中关闭了调试模式,并将环境设置为pro(生产环境)。

其默认控制器代码逻辑简单,仅输出字符串“Hello World”。


<?php public function actionIndex() { return 'Hello World'; }

接下来是CodeIgniter框架的测试环节。

该框架的默认控制器代码同样被简化为输出“Hello World”。


<?php public function index() { echo 'Hello World'; }

随后对MixPHP框架进行测试。

MixPHP的默认控制器代码也保持一致,输出“Hello World”。


public function actionIndex() { return 'Hello World'; }

正式进入测试阶段。

首先测试Yii框架,测得QPS(每秒查询率)为56.40。


C:/Server/apache24vc11/bin>ab -n 5000 -c 100 http://www.b.com/ This is ApacheBench, Version 2.3 <$Revision: 1757674 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.b.com (be patient) Completed 500 requests Completed 1000 requests Completed 1500 requests Completed 2000 requests Completed 2500 requests Completed 3000 requests Completed 3500 requests Completed 4000 requests Completed 4500 requests Completed 5000 requests Finished 5000 requests Server Software: Apache/2.2.32 Server Hostname: www.b.com Server Port:  80 Document Path:  / Document Length: 9 bytes Concurrency Level: 100 Time taken for tests: 88.659 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 1080000 bytes HTML transferred: 45000 bytes Requests per second: 56.40 [#/sec] (mean) Time per request: 1773.170 [ms] (mean) Time per request: 17.732 [ms] (mean, across all concurrent requests) Transfer rate:  11.90 [Kbytes/sec] received Connection Times (ms)  min mean[+/-sd] median max Connect: 0 0 1.0 1 29 Processing: 14 1765 4200.5 688 48084 Waiting: 14 1610 3741.9 682 46690 Total:  14 1766 4200.5 688 48084 WARNING: The median and mean for the initial connection time are not within a normal deviation  These results are probably not that reliable. Percentage of the requests served within a certain time (ms) 50% 688 66% 1087 75% 1400 80% 1657 90% 3029 95% 7665 98% 14760 99% 24300 100% 48084 (longest request)

其次测试CodeIgniter框架,测得QPS为144.42。


C:/Server/apache24vc11/bin>ab -n 5000 -c 100 http://www.c.com/ This is ApacheBench, Version 2.3 <$Revision: 1757674 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.c.com (be patient) Completed 500 requests Completed 1000 requests Completed 1500 requests Completed 2000 requests Completed 2500 requests Completed 3000 requests Completed 3500 requests Completed 4000 requests Completed 4500 requests Completed 5000 requests Finished 5000 requests Server Software: Apache/2.2.32 Server Hostname: www.c.com Server Port:  80 Document Path:  / Document Length: 8 bytes Concurrency Level: 100 Time taken for tests: 34.621 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 1075000 bytes HTML transferred: 40000 bytes Requests per second: 144.42 [#/sec] (mean) Time per request: 692.419 [ms] (mean) Time per request: 6.924 [ms] (mean, across all concurrent requests) Transfer rate:  30.32 [Kbytes/sec] received Connection Times (ms)  min mean[+/-sd] median max Connect: 0 0 0.7 1 22 Processing: 8 689 1014.3 480 13324 Waiting: 8 686 1012.2 478 13324 Total:  9 689 1014.3 480 13325 WARNING: The median and mean for the initial connection time are not within a normal deviation  These results are probably not that reliable. Percentage of the requests served within a certain time (ms) 50% 480 66% 673 75% 810 80% 902 90% 1238 95% 1808 98% 3336 99% 6037 100% 13325 (longest request)

最后测试MixPHP框架,测得QPS高达440.48。


C:/Server/apache24vc11/bin>ab -n 5000 -c 100 http://www.a.com/ This is ApacheBench, Version 2.3 <$Revision: 1757674 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.a.com (be patient) Completed 500 requests Completed 1000 requests Completed 1500 requests Completed 2000 requests Completed 2500 requests Completed 3000 requests Completed 3500 requests Completed 4000 requests Completed 4500 requests Completed 5000 requests Finished 5000 requests Server Software: Apache/2.2.32 Server Hostname: www.a.com Server Port:  80 Document Path:  / Document Length: 12 bytes Concurrency Level: 100 Time taken for tests: 11.351 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 1025000 bytes HTML transferred: 60000 bytes Requests per second: 440.48 [#/sec] (mean) Time per request: 227.026 [ms] (mean) Time per request: 2.270 [ms] (mean, across all concurrent requests) Transfer rate:  88.18 [Kbytes/sec] received Connection Times (ms)  min mean[+/-sd] median max Connect: 0 1 0.9 1 25 Processing: 4 222 822.4 15 10376 Waiting: 4 221 822.4 14 10376 Total:  4 222 822.4 16 10376 Percentage of the requests served within a certain time (ms) 50% 16 66% 69 75% 214 80% 364 90% 561 95% 762 98% 978 99% 1829 100% 10376 (longest request)

根据测试结果得出结论。

由于虚拟机文件IO性能较差,当Yii尝试处理300并发时直接失去响应,故被迫降低至100并发。即便在同等架构限制下,MixPHP的性能表现依然领先。

欢迎读者自行验证,项目地址为:https://github.com/mixstart/mixPHP。

ITEM DESC
Yii 56.40 QPS
CodeIgniter 144.42 QPS
MixPHP 440.48 QPS

总结部分回顾全文。

以上内容即为本次对比的全部细节,希望能为相关学习或工作提供参考。如有任何疑问,欢迎留言交流,感谢支持。

上一篇
PHP集成Memcached缓存服务:安装、配置与应用实战

Memcached是一款高性能的分布式内存缓存服务器,旨在通过减少数据库访问来提升动态Web应用速度与可扩展性。本文详解在Linux环境下编译安装Memcached及libevent依赖库的过程,解析守护进程启动参数。针对PHP客户端接入,对比了memcache扩展与php-memcached-client两种方式并推荐后者。文章最后通过具体代码示例,演示如何利用add、get等方法实现数据库查询结果缓存及多服务器Session共享,有效降低MySQL负载。

下一篇
Smarty缓存控制技巧:insert、register_function与register_block详解

Smarty提供了强大的缓存功能,但有时需要选择性缓存部分内容。本文介绍三种控制缓存输出的方法:使用insert函数使模板局部不缓存、通过register_function阻止插件输出被缓存、利用register_block使页面某块不被缓存。对比发现insert默认不缓存且无需注册,而register_function和register_block需显式设置false参数并注意注册时机,以避免is_cached()调用错误。

相关文章

更多
使用Apache ab进行HTTP性能测试

本文介绍如何使用Apache自带的ab工具进行HTTP性能测试。Mac系统默认包含Apache环境,可通过终端命令启动并验证;Windows用户需从官网下载或编译安装。文章详细解析了ab命令的核心参数,如-n指定请求总数、-c设置并发数、-t设定超时时间等,并提供了具体的测试命令示例及结果解读方法,帮助用户快速掌握服务器响应能力的评估技巧。

2026.07.18 964
PHP中json_encode、json_decode与serialize、unserialize的性能测试分析

本文通过实验对比了PHP 5.2.13和5.3.2环境下json_encode/decode与serialize/unserialize的执行效率。结果显示,JSON编码解码并未比内置序列化更高效,反序列化时两者性能相差约两倍,且PHP 5.3相比5.2有轻微提升。

2025.09.15 793
PHP四种基础排序算法运行时间对比

本文通过PHP代码实现冒泡、选择、插入和快速四种基础排序算法,并记录其执行耗时。测试结果显示,随着数据量增加,快速排序在效率上显著优于其他三种算法,而冒泡与选择排序因时间复杂度较高,在处理大规模数据时表现较差。

2025.07.20 718
Apache AB性能测试工具使用教程

Apache服务器自带的ab(ApacheBench)工具专门用于HTTP Server的benchmark testing,可同时模拟多个并发请求进行负载测试。本文整理其基本用法、运行结果解读及常用参数说明,帮助开发者快速掌握该轻量级测试工具的操作方法。

2026.07.30 625
Smarty模板嵌套:include与fetch性能实测对比

本文通过Apache ab工具对Smarty模板中{include}与$smarty->fetch()两种嵌套方式进行了性能对比。在单个子模板场景下,两者耗时差异仅约1.3%,但include波动较大;在十个子模板场景下,fetch表现更稳定且资源占用相对可控。测试表明,尽管fetch在极端嵌套下可能增加实例开销,但在实际复杂应用中,其带来的模块解耦和变量隔离优势使其成为更可靠的选择,具体方案需结合系统复杂度权衡。

2025.01.11 612
PHP各类Hash算法长度与性能基准测试

本文通过PHP代码对多种哈希算法的输出长度及执行性能进行实测。结果显示MD5、SHA1等经典算法输出固定位数,而FNV系列和CRC32在运算速度上显著优于SHA256等高安全级别算法。文中附带在线哈希加密工具链接,便于开发者快速验证数据完整性。

2026.04.07 597

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。