소스 검색

[php] Phpixie add Adapterman variant (#10026)

Joan Miquel 1 개월 전
부모
커밋
6aca8ddd4b

+ 24 - 1
frameworks/PHP/phpixie/benchmark_config.json

@@ -14,7 +14,7 @@
       "database": "MySQL",
       "framework": "phpixie",
       "language": "PHP",
-      "flavor": "PHP7",
+      "flavor": "PHP8",
       "orm": "Full",
       "platform": "FPM/FastCGI",
       "webserver": "nginx",
@@ -23,6 +23,29 @@
       "display_name": "phpixie",
       "notes": "",
       "versus": "php"
+    },
+    "workerman": {
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortunes",
+      "update_url": "/updates?queries=",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "MySQL",
+      "framework": "phpixie",
+      "language": "PHP",
+      "flavor": "PHP8",
+      "orm": "Full",
+      "platform": "workerman",
+      "webserver": "none",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "phpixie [workerman]",
+      "notes": "",
+      "versus": "php"
     }
   }]
 }

+ 16 - 0
frameworks/PHP/phpixie/deploy/conf/adapterman.ini

@@ -0,0 +1,16 @@
+opcache.enable=1
+opcache.enable_cli=1
+opcache.validate_timestamps=0
+opcache.save_comments=0
+opcache.enable_file_override=1
+opcache.memory_consumption=256
+opcache.interned_strings_buffer=16
+opcache.huge_code_pages=1
+
+mysqlnd.collect_statistics = Off
+memory_limit = 512M
+
+opcache.jit_buffer_size=128M
+opcache.jit=tracing
+
+disable_functions=header,header_remove,headers_sent,headers_list,http_response_code,setcookie,session_create_id,session_id,session_name,session_save_path,session_status,session_start,session_write_close,session_regenerate_id,session_unset,session_get_cookie_params,session_set_cookie_params,set_time_limit

+ 26 - 0
frameworks/PHP/phpixie/phpixie-workerman.dockerfile

@@ -0,0 +1,26 @@
+FROM ubuntu:24.04
+
+ARG DEBIAN_FRONTEND=noninteractive
+
+RUN apt-get update -yqq && apt-get install -yqq software-properties-common > /dev/null
+RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
+RUN apt-get update -yqq > /dev/null && \
+    apt-get install -yqq nginx git unzip php8.0 php8.0-common php8.0-cli php8.0-mysql php8.0-xml php8.0-curl > /dev/null
+
+COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
+
+RUN apt-get install -y php-pear php8.0-dev libevent-dev > /dev/null
+RUN pecl install event-3.1.4 > /dev/null && echo "extension=event.so" > /etc/php/8.0/cli/conf.d/event.ini
+
+COPY deploy/conf/adapterman.ini /etc/php/8.0/cli/conf.d/20-adapterman.ini
+
+WORKDIR /phpixie
+COPY --link . .
+
+RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
+RUN composer require joanhey/adapterman:^0.6 --quiet
+
+RUN chmod -R 777 /phpixie
+
+EXPOSE 8080
+CMD php server.php start

+ 2 - 2
frameworks/PHP/phpixie/phpixie.dockerfile

@@ -1,4 +1,4 @@
-FROM ubuntu:22.04
+FROM ubuntu:24.04
 
 ARG DEBIAN_FRONTEND=noninteractive
 
@@ -11,8 +11,8 @@ COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
 
 COPY deploy/conf/* /etc/php/8.0/fpm/
 
-ADD ./ /phpixie
 WORKDIR /phpixie
+COPY --link . .
 
 RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/8.0/fpm/php-fpm.conf ; fi;
 

+ 47 - 0
frameworks/PHP/phpixie/server.php

@@ -0,0 +1,47 @@
+<?php
+require_once __DIR__ . '/vendor/autoload.php';
+
+
+use Adapterman\Adapterman;
+use Workerman\Worker;
+use Workerman\Timer;
+
+Adapterman::init();
+
+$http_worker                = new Worker('http://0.0.0.0:8080');
+$http_worker->count         = (int) shell_exec('nproc') * 4;
+$http_worker->reusePort     = true;
+$http_worker->name          = 'AdapterMan Phpixie';
+
+$http_worker->onWorkerStart = static function () {
+    HeaderDate::init();
+    //chdir(__DIR__.'/public');
+    require 'web/start.php';
+};
+
+$http_worker->onMessage = static function ($connection) {
+
+    $connection->send(run());
+};
+
+Worker::runAll();
+
+class HeaderDate
+{
+    const NAME = 'Date: ';
+
+    /**
+     * Date header
+     *
+     * @var string
+     */
+    public static $date;
+
+    public static function init(): void
+    {
+        self::$date = self::NAME . gmdate(DATE_RFC7231);
+        Timer::add(1, static function() {
+            self::$date = self::NAME . gmdate(DATE_RFC7231);
+        });
+    }
+}

+ 19 - 0
frameworks/PHP/phpixie/web/start.php

@@ -0,0 +1,19 @@
+<?php
+$root = dirname(__DIR__);
+$loader = require $root.'/vendor/autoload.php';
+$loader->add('', $root.'/classes/');
+
+global $pixie;
+$pixie = new \App\Pixie();
+$pixie->bootstrap($root);
+
+function run(): string
+{
+    global $pixie;
+    ob_start();
+
+    $pixie->handle_http_request();
+    header(HeaderDate::$date); // To pass the bench, nginx auto add it
+
+    return ob_get_clean();
+}