Skip to content

Commit c956902

Browse files
authored
[php] Update imi version (#7705)
* Upgrade swoole version * Fix
1 parent d0bf6c2 commit c956902

File tree

6 files changed

+129
-165
lines changed

6 files changed

+129
-165
lines changed

frameworks/PHP/imi/benchmark_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"versus": "Workerman"
9898
},
9999
"swoole-pgsql": {
100-
"dockerfile": "imi-swoole-pgsql.dockerfile",
100+
"dockerfile": "imi-swoole.dockerfile",
101101
"db_url": "/pgDbModel",
102102
"query_url": "/pgQueryModel?queries=",
103103
"fortune_url": "/pgFortunes",
@@ -119,7 +119,7 @@
119119
"versus": "Swoole"
120120
},
121121
"swoole-pgsql-raw": {
122-
"dockerfile": "imi-swoole-pgsql.dockerfile",
122+
"dockerfile": "imi-swoole.dockerfile",
123123
"db_url": "/pgDbRaw",
124124
"query_url": "/pgQueryRaw?queries=",
125125
"fortune_url": "/pgFortunesRaw",

frameworks/PHP/imi/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"require": {
3-
"imiphp/imi": "~2.0",
4-
"imiphp/imi-pgsql": "~2.0"
3+
"imiphp/imi": "~2.1.0",
4+
"imiphp/imi-pgsql": "~2.1.0"
55
},
66
"autoload": {
77
"psr-4" : {

frameworks/PHP/imi/config/config.php

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,126 @@
11
<?php
22

33
use Imi\App;
4+
use function Imi\env;
45

5-
$mode = App::isInited() ? App::getApp()->getType() : '';
6-
$isMysql = ('mysql' === strtolower(getenv('TFB_TEST_DATABASE') ?: 'mysql'));
7-
$host = 'tfb-database';
8-
$username = 'benchmarkdbuser';
9-
$password = 'benchmarkdbpass';
6+
return (function() {
7+
$mode = App::isInited() ? App::getApp()->getType() : '';
8+
$isMysql = ('mysql' === strtolower(env('TFB_TEST_DATABASE', 'mysql')));
109

11-
return [
12-
// 项目根命名空间
13-
'namespace' => 'ImiApp',
10+
return [
11+
// 项目根命名空间
12+
'namespace' => 'ImiApp',
1413

15-
// 配置文件
16-
'configs' => [
17-
'beans' => __DIR__ . '/beans.php',
18-
],
19-
20-
// 组件命名空间
21-
'components' => [],
22-
23-
// 主服务器配置
24-
'mainServer' => 'swoole' === $mode ? [
25-
'namespace' => 'ImiApp\ApiServer',
26-
'type' => Imi\Swoole\Server\Type::HTTP,
27-
'host' => '0.0.0.0',
28-
'port' => 8080,
29-
'mode' => SWOOLE_BASE,
30-
'configs' => [
31-
'worker_num' => swoole_cpu_num(),
32-
'open_tcp_nodelay' => true,
33-
'tcp_fastopen' => true,
34-
'http_parse_post' => false,
35-
'http_parse_cookie' => false,
36-
'http_parse_files' => false,
37-
'http_compression' => false,
14+
// 配置文件
15+
'configs' => [
16+
'beans' => __DIR__ . '/beans.php',
3817
],
39-
] : [],
4018

41-
// Workerman 服务器配置
42-
'workermanServer' => 'workerman' === $mode ? [
43-
// 服务器名,http 也可以改成 abc 等等,完全自定义
44-
'http' => [
45-
// 指定服务器命名空间
46-
'namespace' => 'ImiApp\ApiServer',
47-
// 服务器类型
48-
'type' => Imi\Workerman\Server\Type::HTTP, // HTTP、WEBSOCKET、TCP、UDP
49-
'host' => '0.0.0.0',
50-
'port' => 8080,
51-
// socket的上下文选项,参考:http://doc3.workerman.net/315128
52-
'context' => [],
53-
'configs' => [
54-
// 支持设置 Workerman 参数
55-
'count' => (int) shell_exec('nproc') * 4,
56-
],
57-
],
58-
] : [],
19+
// 组件命名空间
20+
'components' => [],
5921

60-
'db' => [
61-
'defaultPool' => $isMysql ? 'mysql' : 'pgsql', // 默认连接池
62-
'connections' => [
63-
'mysql' => [
64-
'host' => $host,
65-
'username' => $username,
66-
'password' => $password,
67-
'database' => 'hello_world',
68-
'dbClass' => \Imi\Db\Mysql\Drivers\Mysqli\Driver::class,
69-
'checkStateWhenGetResource' => false,
22+
// 主服务器配置
23+
'mainServer' => 'swoole' === $mode ? [
24+
'namespace' => 'ImiApp\ApiServer',
25+
'type' => Imi\Swoole\Server\Type::HTTP,
26+
'host' => '0.0.0.0',
27+
'port' => 8080,
28+
'mode' => SWOOLE_BASE,
29+
'configs' => [
30+
'worker_num' => swoole_cpu_num(),
31+
'open_tcp_nodelay' => true,
32+
'tcp_fastopen' => true,
33+
'http_parse_post' => false,
34+
'http_parse_cookie' => false,
35+
'http_parse_files' => false,
36+
'http_compression' => false,
7037
],
71-
'pgsql' => [
72-
'host' => $host,
73-
'username' => $username,
74-
'password' => $password,
75-
'database' => 'hello_world',
76-
'dbClass' => \Imi\Pgsql\Db\Drivers\PdoPgsql\Driver::class,
77-
'checkStateWhenGetResource' => false,
78-
],
79-
],
80-
],
38+
] : [],
8139

82-
'pools' => 'swoole' === $mode ? [
83-
// 连接池名称
84-
'mysql' => [
85-
'pool' => [
86-
'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
87-
'config' => [
88-
// 池子中最多资源数
89-
'maxResources' => intval(1024 / swoole_cpu_num()),
90-
// 池子中最少资源数
91-
'minResources' => $isMysql ? 16 : 0,
92-
'gcInterval' => 0,
93-
'checkStateWhenGetResource' => false,
40+
// Workerman 服务器配置
41+
'workermanServer' => 'workerman' === $mode ? [
42+
// 服务器名,http 也可以改成 abc 等等,完全自定义
43+
'http' => [
44+
// 指定服务器命名空间
45+
'namespace' => 'ImiApp\ApiServer',
46+
// 服务器类型
47+
'type' => Imi\Workerman\Server\Type::HTTP, // HTTP、WEBSOCKET、TCP、UDP
48+
'host' => '0.0.0.0',
49+
'port' => 8080,
50+
// socket的上下文选项,参考:http://doc3.workerman.net/315128
51+
'context' => [],
52+
'configs' => [
53+
// 支持设置 Workerman 参数
54+
'count' => (int) shell_exec('nproc') * 4,
9455
],
9556
],
96-
// resource也可以定义多个连接
97-
'resource' => [
98-
'host' => $host,
99-
'username' => $username,
100-
'password' => $password,
101-
'database' => 'hello_world',
102-
'dbClass' => \Imi\Swoole\Db\Driver\Swoole\Driver::class,
57+
] : [],
58+
59+
'db' => [
60+
'defaultPool' => $isMysql ? 'mysql' : 'pgsql', // 默认连接池
61+
'connections' => [
62+
'mysql' => [
63+
'host' => env('DB_HOST', 'tfb-database'),
64+
'username' => env('DB_USERNAME', 'benchmarkdbuser'),
65+
'password' => env('DB_PASSWORD', 'benchmarkdbpass'),
66+
'database' => 'hello_world',
67+
'dbClass' => \Imi\Db\Mysql\Drivers\Mysqli\Driver::class,
68+
'checkStateWhenGetResource' => false,
69+
],
70+
'pgsql' => [
71+
'host' => env('DB_HOST', 'tfb-database'),
72+
'username' => env('DB_USERNAME', 'benchmarkdbuser'),
73+
'password' => env('DB_PASSWORD', 'benchmarkdbpass'),
74+
'database' => 'hello_world',
75+
'dbClass' => \Imi\Pgsql\Db\Drivers\PdoPgsql\Driver::class,
76+
'checkStateWhenGetResource' => false,
77+
],
10378
],
10479
],
105-
'pgsql' => [
106-
'pool' => [
107-
'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
108-
'config' => [
109-
// 池子中最多资源数
110-
'maxResources' => intval(1024 / swoole_cpu_num()),
111-
// 池子中最少资源数
112-
'minResources' => $isMysql ? 0 : 16,
113-
'checkStateWhenGetResource' => false,
80+
81+
'pools' => 'swoole' === $mode ? [
82+
// 连接池名称
83+
'mysql' => [
84+
'pool' => [
85+
'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
86+
'config' => [
87+
// 池子中最多资源数
88+
'maxResources' => intval(1024 / swoole_cpu_num()),
89+
// 池子中最少资源数
90+
'minResources' => $isMysql ? 16 : 0,
91+
'gcInterval' => 0,
92+
'checkStateWhenGetResource' => false,
93+
],
94+
],
95+
// resource也可以定义多个连接
96+
'resource' => [
97+
'host' => env('DB_HOST', 'tfb-database'),
98+
'username' => env('DB_USERNAME', 'benchmarkdbuser'),
99+
'password' => env('DB_PASSWORD', 'benchmarkdbpass'),
100+
'database' => 'hello_world',
101+
'dbClass' => \Imi\Swoole\Db\Driver\Swoole\Driver::class,
114102
],
115103
],
116-
// resource也可以定义多个连接
117-
'resource' => [
118-
'host' => $host,
119-
'username' => $username,
120-
'password' => $password,
121-
'database' => 'hello_world',
122-
'dbClass' => \Imi\Pgsql\Db\Drivers\Swoole\Driver::class,
104+
'pgsql' => [
105+
'pool' => [
106+
'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
107+
'config' => [
108+
// 池子中最多资源数
109+
'maxResources' => intval(1024 / swoole_cpu_num()),
110+
// 池子中最少资源数
111+
'minResources' => $isMysql ? 0 : 16,
112+
'checkStateWhenGetResource' => false,
113+
],
114+
],
115+
// resource也可以定义多个连接
116+
'resource' => [
117+
'host' => env('DB_HOST', 'tfb-database'),
118+
'username' => env('DB_USERNAME', 'benchmarkdbuser'),
119+
'password' => env('DB_PASSWORD', 'benchmarkdbpass'),
120+
'database' => 'hello_world',
121+
'dbClass' => \Imi\Pgsql\Db\Drivers\SwooleNew\Driver::class,
122+
],
123123
],
124-
],
125-
] : [],
126-
];
124+
] : [],
125+
];
126+
})();

frameworks/PHP/imi/imi-swoole-pgsql.dockerfile

Lines changed: 0 additions & 37 deletions
This file was deleted.

frameworks/PHP/imi/imi-swoole.dockerfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
FROM php:8.1-cli
22

3-
ENV SWOOLE_VERSION 4.8.3
3+
ENV SWOOLE_VERSION 5.0.1
44
ARG TFB_TEST_DATABASE
55
ENV TFB_TEST_DATABASE=${TFB_TEST_DATABASE}
66

7-
RUN docker-php-ext-install -j$(nproc) opcache > /dev/null
7+
RUN docker-php-ext-install -j$(nproc) opcache
88

9-
RUN apt -yqq update > /dev/null && \
10-
apt -yqq install git unzip > /dev/null
9+
RUN apt -yqq update && \
10+
apt -yqq install git unzip libpq-dev
1111

12-
RUN pecl update-channels
13-
14-
RUN pecl install swoole-${SWOOLE_VERSION} > /dev/null && \
15-
docker-php-ext-enable swoole
12+
RUN cd /tmp && curl -sSL "https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz" | tar xzf - \
13+
&& cd swoole-src-${SWOOLE_VERSION} \
14+
&& phpize && ./configure --enable-swoole-pgsql && make -j install \
15+
&& docker-php-ext-enable swoole
1616

1717
COPY . /imi
1818
COPY php.ini /usr/local/etc/php/
@@ -22,8 +22,8 @@ RUN chmod -R ug+rwx /imi/.runtime
2222
WORKDIR /imi
2323

2424
RUN curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
25-
RUN composer install --no-dev --classmap-authoritative --quiet > /dev/null
26-
RUN composer require imiphp/imi-swoole:~2.0 -W
25+
RUN composer install --no-dev --classmap-authoritative --quiet
26+
RUN composer require imiphp/imi-swoole:~2.1.0 -W
2727
RUN composer dumpautoload -o
2828

2929
EXPOSE 8080

frameworks/PHP/imi/imi-workerman.dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ FROM php:8.1-cli
33
ARG TFB_TEST_DATABASE
44
ENV TFB_TEST_DATABASE=${TFB_TEST_DATABASE}
55

6-
RUN apt -yqq update > /dev/null && \
7-
apt -yqq install git unzip libevent-dev libssl-dev libpq-dev > /dev/null
6+
RUN apt -yqq update && \
7+
apt upgrade -y && \
8+
apt -yqq install git unzip libevent-dev libssl-dev libpq-dev
89

9-
RUN docker-php-ext-install -j$(nproc) opcache mysqli pcntl sockets pdo_pgsql > /dev/null
10+
RUN docker-php-ext-install -j$(nproc) opcache mysqli pcntl sockets pdo_pgsql
1011

1112
RUN pecl update-channels
1213

13-
RUN pecl install event > /dev/null && \
14+
RUN pecl install event && \
1415
echo "extension=event.so" > /usr/local/etc/php/conf.d/event.ini
1516

1617
COPY . /imi
@@ -21,8 +22,8 @@ RUN chmod -R ug+rwx /imi/.runtime
2122
WORKDIR /imi
2223

2324
RUN curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
24-
RUN composer install --no-dev --classmap-authoritative --quiet > /dev/null
25-
RUN composer require imiphp/imi-workerman:~2.0 -W
25+
RUN composer install --no-dev --classmap-authoritative --quiet
26+
RUN composer require imiphp/imi-workerman:~2.1.0 -W
2627
RUN composer dumpautoload -o
2728

2829
EXPOSE 8080

0 commit comments

Comments
 (0)