浏览代码

[php] Update imi version (#7705)

* Upgrade swoole version

* Fix
Yurun 2 年之前
父节点
当前提交
c956902bad

+ 2 - 2
frameworks/PHP/imi/benchmark_config.json

@@ -97,7 +97,7 @@
         "versus": "Workerman"
       },
       "swoole-pgsql": {
-        "dockerfile": "imi-swoole-pgsql.dockerfile",
+        "dockerfile": "imi-swoole.dockerfile",
         "db_url": "/pgDbModel",
         "query_url": "/pgQueryModel?queries=",
         "fortune_url": "/pgFortunes",
@@ -119,7 +119,7 @@
         "versus": "Swoole"
       },
       "swoole-pgsql-raw": {
-        "dockerfile": "imi-swoole-pgsql.dockerfile",
+        "dockerfile": "imi-swoole.dockerfile",
         "db_url": "/pgDbRaw",
         "query_url": "/pgQueryRaw?queries=",
         "fortune_url": "/pgFortunesRaw",

+ 2 - 2
frameworks/PHP/imi/composer.json

@@ -1,7 +1,7 @@
 {
     "require": {
-        "imiphp/imi": "~2.0",
-        "imiphp/imi-pgsql": "~2.0"
+        "imiphp/imi": "~2.1.0",
+        "imiphp/imi-pgsql": "~2.1.0"
     },
     "autoload": {
         "psr-4" : {

+ 108 - 108
frameworks/PHP/imi/config/config.php

@@ -1,126 +1,126 @@
 <?php
 
 use Imi\App;
+use function Imi\env;
 
-$mode = App::isInited() ? App::getApp()->getType() : '';
-$isMysql = ('mysql' === strtolower(getenv('TFB_TEST_DATABASE') ?: 'mysql'));
-$host = 'tfb-database';
-$username = 'benchmarkdbuser';
-$password = 'benchmarkdbpass';
+return (function() {
+    $mode = App::isInited() ? App::getApp()->getType() : '';
+    $isMysql = ('mysql' === strtolower(env('TFB_TEST_DATABASE', 'mysql')));
 
-return [
-    // 项目根命名空间
-    'namespace'    =>    'ImiApp',
+    return [
+        // 项目根命名空间
+        'namespace'    =>    'ImiApp',
 
-    // 配置文件
-    'configs'    =>    [
-        'beans'        =>    __DIR__ . '/beans.php',
-    ],
-
-    // 组件命名空间
-    'components'    =>  [],
-
-    // 主服务器配置
-    'mainServer'    => 'swoole' === $mode ? [
-        'namespace' =>  'ImiApp\ApiServer',
-        'type'      =>  Imi\Swoole\Server\Type::HTTP,
-        'host'      =>  '0.0.0.0',
-        'port'      =>  8080,
-        'mode'      =>  SWOOLE_BASE,
-        'configs'   =>  [
-            'worker_num'        => swoole_cpu_num(),
-            'open_tcp_nodelay'  => true,
-            'tcp_fastopen'      => true,
-            'http_parse_post'   => false,
-            'http_parse_cookie' => false,
-            'http_parse_files'  => false,
-            'http_compression'  => false,
+        // 配置文件
+        'configs'    =>    [
+            'beans'        =>    __DIR__ . '/beans.php',
         ],
-    ] : [],
 
-    // Workerman 服务器配置
-    'workermanServer' => 'workerman' === $mode ? [
-        // 服务器名,http 也可以改成 abc 等等,完全自定义
-        'http' => [
-            // 指定服务器命名空间
-            'namespace' => 'ImiApp\ApiServer',
-            // 服务器类型
-            'type'      => Imi\Workerman\Server\Type::HTTP, // HTTP、WEBSOCKET、TCP、UDP
-            'host'      => '0.0.0.0',
-            'port'      => 8080,
-            // socket的上下文选项,参考:http://doc3.workerman.net/315128
-            'context'   => [],
-            'configs'   => [
-                // 支持设置 Workerman 参数
-                'count' => (int) shell_exec('nproc') * 4,
-            ],
-        ],
-    ] : [],
+        // 组件命名空间
+        'components'    =>  [],
 
-    'db'    => [
-        'defaultPool'   => $isMysql ? 'mysql' : 'pgsql', // 默认连接池
-        'connections'   => [
-            'mysql' => [
-                'host'                        => $host,
-                'username'                    => $username,
-                'password'                    => $password,
-                'database'                    => 'hello_world',
-                'dbClass'                     => \Imi\Db\Mysql\Drivers\Mysqli\Driver::class,
-                'checkStateWhenGetResource'   => false,
+        // 主服务器配置
+        'mainServer'    => 'swoole' === $mode ? [
+            'namespace' =>  'ImiApp\ApiServer',
+            'type'      =>  Imi\Swoole\Server\Type::HTTP,
+            'host'      =>  '0.0.0.0',
+            'port'      =>  8080,
+            'mode'      =>  SWOOLE_BASE,
+            'configs'   =>  [
+                'worker_num'        => swoole_cpu_num(),
+                'open_tcp_nodelay'  => true,
+                'tcp_fastopen'      => true,
+                'http_parse_post'   => false,
+                'http_parse_cookie' => false,
+                'http_parse_files'  => false,
+                'http_compression'  => false,
             ],
-            'pgsql' => [
-                'host'                        => $host,
-                'username'                    => $username,
-                'password'                    => $password,
-                'database'                    => 'hello_world',
-                'dbClass'                     => \Imi\Pgsql\Db\Drivers\PdoPgsql\Driver::class,
-                'checkStateWhenGetResource'   => false,
-            ],
-        ],
-    ],
+        ] : [],
 
-    'pools' => 'swoole' === $mode ? [
-        // 连接池名称
-        'mysql' => [
-            'pool'    =>    [
-                'class'        =>    \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
-                'config'    =>    [
-                    // 池子中最多资源数
-                    'maxResources' => intval(1024 / swoole_cpu_num()),
-                    // 池子中最少资源数
-                    'minResources' => $isMysql ? 16 : 0,
-                    'gcInterval'   => 0,
-                    'checkStateWhenGetResource' =>  false,
+        // Workerman 服务器配置
+        'workermanServer' => 'workerman' === $mode ? [
+            // 服务器名,http 也可以改成 abc 等等,完全自定义
+            'http' => [
+                // 指定服务器命名空间
+                'namespace' => 'ImiApp\ApiServer',
+                // 服务器类型
+                'type'      => Imi\Workerman\Server\Type::HTTP, // HTTP、WEBSOCKET、TCP、UDP
+                'host'      => '0.0.0.0',
+                'port'      => 8080,
+                // socket的上下文选项,参考:http://doc3.workerman.net/315128
+                'context'   => [],
+                'configs'   => [
+                    // 支持设置 Workerman 参数
+                    'count' => (int) shell_exec('nproc') * 4,
                 ],
             ],
-            // resource也可以定义多个连接
-            'resource'    =>    [
-                'host'        => $host,
-                'username'    => $username,
-                'password'    => $password,
-                'database'    => 'hello_world',
-                'dbClass'     => \Imi\Swoole\Db\Driver\Swoole\Driver::class,
+        ] : [],
+
+        'db'    => [
+            'defaultPool'   => $isMysql ? 'mysql' : 'pgsql', // 默认连接池
+            'connections'   => [
+                'mysql' => [
+                    'host'                        => env('DB_HOST', 'tfb-database'),
+                    'username'                    => env('DB_USERNAME', 'benchmarkdbuser'),
+                    'password'                    => env('DB_PASSWORD', 'benchmarkdbpass'),
+                    'database'                    => 'hello_world',
+                    'dbClass'                     => \Imi\Db\Mysql\Drivers\Mysqli\Driver::class,
+                    'checkStateWhenGetResource'   => false,
+                ],
+                'pgsql' => [
+                    'host'                        => env('DB_HOST', 'tfb-database'),
+                    'username'                    => env('DB_USERNAME', 'benchmarkdbuser'),
+                    'password'                    => env('DB_PASSWORD', 'benchmarkdbpass'),
+                    'database'                    => 'hello_world',
+                    'dbClass'                     => \Imi\Pgsql\Db\Drivers\PdoPgsql\Driver::class,
+                    'checkStateWhenGetResource'   => false,
+                ],
             ],
         ],
-        'pgsql' => [
-            'pool'    =>    [
-                'class'        =>    \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
-                'config'    =>    [
-                    // 池子中最多资源数
-                    'maxResources' => intval(1024 / swoole_cpu_num()),
-                    // 池子中最少资源数
-                    'minResources' => $isMysql ? 0 : 16,
-                    'checkStateWhenGetResource' =>  false,
+
+        'pools' => 'swoole' === $mode ? [
+            // 连接池名称
+            'mysql' => [
+                'pool'    =>    [
+                    'class'        =>    \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
+                    'config'    =>    [
+                        // 池子中最多资源数
+                        'maxResources' => intval(1024 / swoole_cpu_num()),
+                        // 池子中最少资源数
+                        'minResources' => $isMysql ? 16 : 0,
+                        'gcInterval'   => 0,
+                        'checkStateWhenGetResource' =>  false,
+                    ],
+                ],
+                // resource也可以定义多个连接
+                'resource'    =>    [
+                    'host'        => env('DB_HOST', 'tfb-database'),
+                    'username'    => env('DB_USERNAME', 'benchmarkdbuser'),
+                    'password'    => env('DB_PASSWORD', 'benchmarkdbpass'),
+                    'database'    => 'hello_world',
+                    'dbClass'     => \Imi\Swoole\Db\Driver\Swoole\Driver::class,
                 ],
             ],
-            // resource也可以定义多个连接
-            'resource'    =>    [
-                'host'        => $host,
-                'username'    => $username,
-                'password'    => $password,
-                'database'    => 'hello_world',
-                'dbClass'     => \Imi\Pgsql\Db\Drivers\Swoole\Driver::class,
+            'pgsql' => [
+                'pool'    =>    [
+                    'class'        =>    \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
+                    'config'    =>    [
+                        // 池子中最多资源数
+                        'maxResources' => intval(1024 / swoole_cpu_num()),
+                        // 池子中最少资源数
+                        'minResources' => $isMysql ? 0 : 16,
+                        'checkStateWhenGetResource' =>  false,
+                    ],
+                ],
+                // resource也可以定义多个连接
+                'resource'    =>    [
+                    'host'        => env('DB_HOST', 'tfb-database'),
+                    'username'    => env('DB_USERNAME', 'benchmarkdbuser'),
+                    'password'    => env('DB_PASSWORD', 'benchmarkdbpass'),
+                    'database'    => 'hello_world',
+                    'dbClass'     => \Imi\Pgsql\Db\Drivers\SwooleNew\Driver::class,
+                ],
             ],
-        ],
-    ] : [],
-];
+        ] : [],
+    ];
+})();

+ 0 - 37
frameworks/PHP/imi/imi-swoole-pgsql.dockerfile

@@ -1,37 +0,0 @@
-FROM php:8.0-cli
-
-ENV SWOOLE_VERSION 4.8.3
-ENV SWOOLE_POSTGRES 4.8.0
-ARG TFB_TEST_DATABASE
-ENV TFB_TEST_DATABASE=${TFB_TEST_DATABASE}
-
-RUN docker-php-ext-install -j$(nproc) opcache > /dev/null
-
-RUN apt -yqq update > /dev/null && \
-    apt -yqq install git unzip libpq-dev > /dev/null
-
-RUN cd /tmp && curl -sSL "https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz" | tar xzf - \
-        && cd swoole-src-${SWOOLE_VERSION} \
-        && phpize && ./configure > /dev/null && make -j > /dev/null && make install > /dev/null \
-        && docker-php-ext-enable swoole
-
-RUN cd /tmp && curl -sSL "https://github.com/swoole/ext-postgresql/archive/v${SWOOLE_POSTGRES}.tar.gz" | tar xzf - \
-        && cd ext-postgresql-${SWOOLE_POSTGRES} \
-        && phpize && ./configure > /dev/null && make -j > /dev/null && make install > /dev/null \
-        && docker-php-ext-enable swoole_postgresql
-
-COPY . /imi
-COPY php.ini /usr/local/etc/php/
-
-RUN chmod -R ug+rwx /imi/.runtime
-
-WORKDIR /imi
-
-RUN curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
-RUN composer install --no-dev --classmap-authoritative --quiet > /dev/null
-RUN composer require imiphp/imi-swoole:~2.0 -W
-RUN composer dumpautoload -o
-
-EXPOSE 8080
-
-CMD ./run-swoole.sh

+ 10 - 10
frameworks/PHP/imi/imi-swoole.dockerfile

@@ -1,18 +1,18 @@
 FROM php:8.1-cli
 
-ENV SWOOLE_VERSION 4.8.3
+ENV SWOOLE_VERSION 5.0.1
 ARG TFB_TEST_DATABASE
 ENV TFB_TEST_DATABASE=${TFB_TEST_DATABASE}
 
-RUN docker-php-ext-install -j$(nproc) opcache > /dev/null
+RUN docker-php-ext-install -j$(nproc) opcache
 
-RUN apt -yqq update > /dev/null && \
-    apt -yqq install git unzip > /dev/null
+RUN apt -yqq update && \
+    apt -yqq install git unzip libpq-dev
 
-RUN pecl update-channels
-
-RUN pecl install swoole-${SWOOLE_VERSION} > /dev/null && \
-    docker-php-ext-enable swoole
+RUN cd /tmp && curl -sSL "https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz" | tar xzf - \
+        && cd swoole-src-${SWOOLE_VERSION} \
+        && phpize && ./configure --enable-swoole-pgsql && make -j install \
+        && docker-php-ext-enable swoole
 
 COPY . /imi
 COPY php.ini /usr/local/etc/php/
@@ -22,8 +22,8 @@ RUN chmod -R ug+rwx /imi/.runtime
 WORKDIR /imi
 
 RUN curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
-RUN composer install --no-dev --classmap-authoritative --quiet > /dev/null
-RUN composer require imiphp/imi-swoole:~2.0 -W
+RUN composer install --no-dev --classmap-authoritative --quiet
+RUN composer require imiphp/imi-swoole:~2.1.0 -W
 RUN composer dumpautoload -o
 
 EXPOSE 8080

+ 7 - 6
frameworks/PHP/imi/imi-workerman.dockerfile

@@ -3,14 +3,15 @@ FROM php:8.1-cli
 ARG TFB_TEST_DATABASE
 ENV TFB_TEST_DATABASE=${TFB_TEST_DATABASE}
 
-RUN apt -yqq update > /dev/null && \
-    apt -yqq install git unzip libevent-dev libssl-dev libpq-dev > /dev/null
+RUN apt -yqq update && \
+    apt upgrade -y && \
+    apt -yqq install git unzip libevent-dev libssl-dev libpq-dev
 
-RUN docker-php-ext-install -j$(nproc) opcache mysqli pcntl sockets pdo_pgsql > /dev/null
+RUN docker-php-ext-install -j$(nproc) opcache mysqli pcntl sockets pdo_pgsql
 
 RUN pecl update-channels
 
-RUN pecl install event > /dev/null && \
+RUN pecl install event && \
     echo "extension=event.so" > /usr/local/etc/php/conf.d/event.ini
 
 COPY . /imi
@@ -21,8 +22,8 @@ RUN chmod -R ug+rwx /imi/.runtime
 WORKDIR /imi
 
 RUN curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
-RUN composer install --no-dev --classmap-authoritative --quiet > /dev/null
-RUN composer require imiphp/imi-workerman:~2.0 -W
+RUN composer install --no-dev --classmap-authoritative --quiet
+RUN composer require imiphp/imi-workerman:~2.1.0 -W
 RUN composer dumpautoload -o
 
 EXPOSE 8080