MixPHP/Yii/CodeIgniter 并发压力测试

本文对比测试了MixPHP、CodeIgniter及Yii三个PHP框架的性能。在相同的测试环境下,MixPHP表现出最高的QPS(每秒查询率),达到440.48,远超其他两个框架。

MixPHP 是一个基于 Swoole 的高性能框架,CodeIgniter 是一个元老级的轻量级框架,Yii 是一个非常流行的框架,以下是三个框架的对比。

由于 Yii/CodeIgniter 是基于 Apache/PHP-FPM 的传统框架,如果使用 MixPHP 的正常 Swoole 部署方式来对比,显得有些不公平,由于 MixPHP 同时支持在 Apache/PHP-FPM 中运行,所以此次测试的 MixPHP 是部署在 Apache 之中。

环境

虚拟机: 4 核,1G
使用 ab 工具压测,命令:ab -n 5000 -c 100 URL

Yii

Yii 关闭了 debug,并设置为 pro 环境。

默认控制器代码如下,输出一个 Hello World。

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

CodeIgniter

默认控制器代码如下,输出一个 Hello World。

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

MixPHP

默认控制器代码如下,输出一个 Hello World。

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

开始测试

  1. 测试 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)
  1. 测试 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)
  1. 测试 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

ITEMDESC
Yii56.40 QPS
CodeIgniter144.42 QPS
MixPHP440.48 QPS
<think>我们正在处理用户关于VSCode运行Yii应用时提示需要选择应用程序的问题。根据引用[1],我们知道VSCode可以通过安装插件来增强功能,特别是ErrorLens可以直接显示错误提示和解决方案。但是用户的问题是关于运行Yii框架时提示需要选择应用程序,这通常与调试配置有关。在VSCode中运行PHP应用(如Yii框架)通常需要配置调试环境。常见的步骤包括:1.确保已安装PHP和必要的扩展(如Xdebug)。2.在VSCode中安装PHPDebug插件。3.配置launch.json文件,指定要运行的脚本或应用程序入口。用户遇到的提示“需要选择应用程序”可能是因为没有正确配置启动配置(launchconfiguration),或者没有选择正确的启动配置。因此,我们可以按照以下步骤来解决问题:步骤1:安装必要的插件-确保已安装“PHPDebug”插件。可以通过扩展市场搜索安装。步骤2:配置Xdebug-在php.ini中启用Xdebug,并配置相关参数,例如:```[XDebug]zend_extension="path/to/xdebug.so"#或.dll(Windows)xdebug.mode=debugxdebug.start_with_request=yes```步骤3:配置VSCode的launch.json-打开VSCode,进入调试视图(Ctrl+Shift+D或点击左侧调试图标)。-点击“创建一个launch.json文件”(如果还没有的话),选择“PHP”环境。-在生成的launch.json中,可以配置多种启动方式。对于Yii框架,通常使用“Launchcurrentlyopenscript”可能不够,因为Yii有一个统一的入口文件(比如index.php)。因此,我们可以添加一个配置来指定入口文件:```json{"name":"LaunchYiiApplication","type":"php","request":"launch","program":"${workspaceFolder}/path/to/your/yii/entry/script",//通常为web/index.php或index.php"cwd":"${workspaceFolder}","port":9003//确保与Xdebug配置的端口一致}```注意:具体路径根据项目结构而定。步骤4:选择正确的启动配置并运行-在调试视图的顶部,选择我们刚刚配置的“LaunchYiiApplication”配置。-按F5启动调试。如果用户使用的是Yii框架的命令行应用(例如控制台命令),则可能需要配置另一个启动配置来运行控制台命令:```json{"name":"RunYiiConsoleCommand","type":"php","request":"launch","program":"${workspaceFolder}/yii",//Yii控制台脚本"args":["your/command","arg1","arg2"],"cwd":"${workspaceFolder}"}```另外,引用[3]提到了不同语言的特点,虽然这里我们使用PHP,但VSCode的调试配置思路是类似的。如果用户按照以上步骤配置后仍然遇到问题,可能需要检查:-Xdebug是否安装正确(可以通过phpinfo()查看)。-端口是否匹配(Xdebug默认端口9000,但VSCode的PHPDebug插件默认使用9003,注意避免冲突)。最后,引用[2]提到模块导入的方式,虽然与PHP无关,但提醒我们可能需要检查项目中的依赖是否完整(例如通过composer安装的依赖)。因此,我们给出解决方案后,可以生成相关问题,帮助用户深入理解。</think>### 在VSCode中运行Yii框架时提示需要选择应用程序的解决方案 在VSCode中运行Yii应用时出现"需要选择应用程序"的提示,通常是由于**调试配置未正确设置**或**PHP环境未正确识别**导致的。请按照以下步骤解决: #### 1. 安装必要插件 - 安装 **PHP Debug** 扩展(Felix Becker出品): ```bash [扩展ID: felixfbecker.php-debug] ``` - 安装 **PHP Intelephense** 扩展(增强PHP支持)[^1] #### 2. 配置调试环境(关键步骤) 在项目根目录创建/修改`.vscode/launch.json`: ```json { "version": "0.2.0", "configurations": [ { "name": "Launch Yii Application", "type": "php", "request": "launch", "program": "${workspaceFolder}/web/index.php", // Yii入口文件 "cwd": "${workspaceFolder}", "port": 9003, "runtimeArgs": [ "-S", "localhost:8000" // 本地调试端口 ] } ] } ``` #### 3. 配置PHP环境 1. 确认`php.ini`已启用Xdebug: ```ini [XDebug] zend_extension=xdebug.so xdebug.mode=debug xdebug.start_with_request=yes ``` 2. 在VSCode设置中指定PHP路径: ```json "php.validate.executablePath": "/usr/bin/php" // 替换为实际路径 ``` #### 4. 启动调试流程 1. 按`F5`启动调试 2. 当出现选择提示时: - 选择 **"Launch Yii Application"** 配置 - 勾选 **"Remember my decision"** 避免重复提示 #### 5. 验证配置 在Yii控制器中添加测试断点: ```php public function actionTest() { $test = "Debug Success"; // 在此行设置断点 echo $test; } ``` 访问`http://localhost:8000?r=test`应触发断点[^1] > **常见问题排查**: > - 确保Xdebug版本与PHP版本匹配(`php -v`查看) > - 检查防火墙是否放行9003端口 > - Yii高级应用需修改`program`路径为`/frontend/web/index.php`
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值