Browse Source

[php] Update Flight and add Workerman variant (#9598)

Joan Miquel 5 months ago
parent
commit
a1957e0a7b

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

@@ -23,6 +23,29 @@
       "display_name": "flight",
       "display_name": "flight",
       "notes": "",
       "notes": "",
       "versus": "php"
       "versus": "php"
-    } 
+    },
+    "workerman": {
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "db_url": "/db",
+      "fortune_url": "/fortunes",
+      "query_url": "/db-multiple?queries=",
+      "update_url": "/updates?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "MySQL",
+      "framework": "Flight",
+      "language": "PHP",
+      "flavor": "PHP8",
+      "orm": "Raw",
+      "platform": "workerman",
+      "webserver": "none",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "flight [workerman]",
+      "notes": "",
+      "versus": "php"
+    }
   }]
   }]
 }
 }

+ 1 - 1
frameworks/PHP/flight/composer.json

@@ -1,5 +1,5 @@
 {
 {
     "require": {
     "require": {
-        "mikecao/flight": "^3.0"
+        "flightphp/core": "^3.14"
     }
     }
 }
 }

+ 16 - 0
frameworks/PHP/flight/deploy/conf/cli-php.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

+ 32 - 0
frameworks/PHP/flight/flight-workerman.dockerfile

@@ -0,0 +1,32 @@
+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.4 php8.4-common php8.4-cli php8.4-fpm php8.4-mysql  > /dev/null
+
+COPY deploy/conf/* /etc/php/8.4/fpm/
+
+WORKDIR /flight
+COPY . .
+
+ENV FLIGHT_DIR="/flight/src"
+
+COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
+
+RUN apt-get install -y php-pear php8.4-dev libevent-dev php8.4-xml > /dev/null
+RUN pecl install event-3.1.4 > /dev/null && echo "extension=event.so" > /etc/php/8.4/cli/conf.d/event.ini
+
+RUN composer require joanhey/adapterman:^0.7
+RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
+
+RUN sed -i "s|Flight::start() ;|//Flight::start() ;|g" index.php
+
+RUN chmod -R 777 /flight
+
+EXPOSE 8080
+
+CMD php -c deploy/conf/cli-php.ini \
+    server.php start

+ 11 - 1
frameworks/PHP/flight/index.php

@@ -3,6 +3,7 @@ require_once 'vendor/autoload.php';
 
 
 error_reporting(-1);
 error_reporting(-1);
 
 
+Flight::set('flight.content_length', false);
 Flight::register('db', PDO::class, [ 'mysql:host=tfb-database;port=3306;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', [ \PDO::ATTR_PERSISTENT => TRUE ] ]);
 Flight::register('db', PDO::class, [ 'mysql:host=tfb-database;port=3306;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', [ \PDO::ATTR_PERSISTENT => TRUE ] ]);
 
 
 // JSON test
 // JSON test
@@ -102,4 +103,13 @@ Flight::route('/fortunes', function() {
     Flight::render('fortunes.php', [ 'fortunes' => $fortunes ]);
     Flight::render('fortunes.php', [ 'fortunes' => $fortunes ]);
 });
 });
 
 
-Flight::start();
+Flight::start() ;
+
+// Workerman
+function run()
+{
+    ob_start();
+    Flight::start();
+    header(HeaderDate::$date); // To pass the bench, nginx auto add it
+    return ob_get_clean();
+}

+ 44 - 0
frameworks/PHP/flight/server.php

@@ -0,0 +1,44 @@
+<?php
+require_once __DIR__.'/vendor/autoload.php';
+
+use Adapterman\Adapterman;
+use Workerman\Lib\Timer;
+use Workerman\Worker;
+
+Adapterman::init();
+
+$http_worker        = new Worker('http://0.0.0.0:8080');
+$http_worker->count = (int) shell_exec('nproc') * 4;
+$http_worker->name  = 'AdapterMan-Flight';
+
+$http_worker->onWorkerStart = static function () {
+    HeaderDate::init();
+    require __DIR__.'/index.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('D, d M Y H:i:s').' GMT';
+        Timer::add(1, static function () {
+            self::$date = self::NAME.gmdate('D, d M Y H:i:s').' GMT';
+        });
+    }
+}