Browse Source

[Ubiquity] add micro version with ngx (#6736)

* add micro approach to ngx

* Update ubiquity-ngx-micro.dockerfile

* [ci skip] set classification to micro
J-C HERON 4 years ago
parent
commit
4c07d61a5c

+ 37 - 0
frameworks/PHP/ubiquity/app/config/bootstrap.php

@@ -0,0 +1,37 @@
+<?php
+use Ubiquity\devtools\cmd\ConsoleFormatter as Console;
+use Ubiquity\cache\CacheManager;
+
+//Comments
+
+//For development mode initialization
+function _dev($devtools, $config)
+{
+    echo Console::showInfo("Development mode");
+}
+
+//For Production mode initialization
+//Create and store dynamic routes.
+function _prod($devtools, $config)
+{
+    echo Console::showInfo("Production mode for benchmark");
+
+    CacheManager::start($config);
+    CacheManager::clearCache($config);
+    include ROOT.DS.'config'.DS.'microApp.php';
+    CacheManager::storeDynamicRoutes(false);
+    echo Console::showMessage('Dynamic routes created!', 'success');
+    $devtools->run('composer', 'optimize');
+}
+
+//Executed before all modes
+function bs_before($devtools, $config)
+{
+}
+
+//Executed after all modes
+function bs_after($devtools, $config)
+{
+    //Initialize all caches
+    //$devtools->run('init-cache');
+}

+ 21 - 0
frameworks/PHP/ubiquity/app/config/microApp.php

@@ -0,0 +1,21 @@
+<?php
+use Ubiquity\controllers\Router;
+
+/**
+ * **************************
+ * Ubiquity micro application
+ * **************************
+ */
+
+Router::get('micro/json', function () {
+    \Ubiquity\utils\http\UResponse::setContentType('application/json');
+    echo \json_encode([
+        'message' => 'Hello, World!'
+    ]);
+});
+
+Router::get('micro/plaintext', function () {
+    \Ubiquity\utils\http\UResponse::setContentType('text/plain', 'utf-8');
+    echo 'Hello, World!';
+});
+

+ 25 - 6
frameworks/PHP/ubiquity/benchmark_config.json

@@ -60,7 +60,7 @@
         "database": "Postgres",
         "database": "Postgres",
         "framework": "ubiquity",
         "framework": "ubiquity",
         "language": "PHP",
         "language": "PHP",
-        "flavor": "PHP7",
+        "flavor": "PHP8",
         "orm": "Full",
         "orm": "Full",
         "platform": "swoole",
         "platform": "swoole",
         "webserver": "none",
         "webserver": "none",
@@ -81,7 +81,7 @@
         "database": "MYSQL",
         "database": "MYSQL",
         "framework": "ubiquity",
         "framework": "ubiquity",
         "language": "PHP",
         "language": "PHP",
-        "flavor": "PHP7",
+        "flavor": "PHP8",
         "orm": "Full",
         "orm": "Full",
         "platform": "swoole",
         "platform": "swoole",
         "webserver": "none",
         "webserver": "none",
@@ -104,7 +104,7 @@
         "database": "Postgres",
         "database": "Postgres",
         "framework": "Ubiquity",
         "framework": "Ubiquity",
         "language": "PHP",
         "language": "PHP",
-        "flavor": "PHP7",
+        "flavor": "PHP8",
         "orm": "Full",
         "orm": "Full",
         "platform": "RoadRunner",
         "platform": "RoadRunner",
         "webserver": "none",
         "webserver": "none",
@@ -125,7 +125,7 @@
         "database": "Mysql",
         "database": "Mysql",
         "framework": "Ubiquity",
         "framework": "Ubiquity",
         "language": "PHP",
         "language": "PHP",
-        "flavor": "PHP7",
+        "flavor": "PHP8",
         "orm": "Full",
         "orm": "Full",
         "platform": "RoadRunner",
         "platform": "RoadRunner",
         "webserver": "none",
         "webserver": "none",
@@ -213,7 +213,7 @@
         "database": "Postgres",
         "database": "Postgres",
         "framework": "Ubiquity",
         "framework": "Ubiquity",
         "language": "PHP",
         "language": "PHP",
-        "flavor": "PHP7",
+        "flavor": "PHP8",
         "orm": "Full",
         "orm": "Full",
         "platform": "ngx_php",
         "platform": "ngx_php",
         "webserver": "nginx",
         "webserver": "nginx",
@@ -234,7 +234,7 @@
         "database": "Postgres",
         "database": "Postgres",
         "framework": "Ubiquity",
         "framework": "Ubiquity",
         "language": "PHP",
         "language": "PHP",
-        "flavor": "PHP7",
+        "flavor": "PHP8",
         "orm": "raw",
         "orm": "raw",
         "platform": "ngx_php",
         "platform": "ngx_php",
         "webserver": "nginx",
         "webserver": "nginx",
@@ -243,6 +243,25 @@
         "display_name": "ubiquity-ngx-raw",
         "display_name": "ubiquity-ngx-raw",
         "notes": "",
         "notes": "",
         "versus": "ngx_php"
         "versus": "ngx_php"
+      },
+      "ngx-micro": {
+        "json_url": "/micro/json",
+        "plaintext_url": "/micro/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "None",
+        "framework": "Ubiquity",
+        "language": "PHP",
+        "flavor": "PHP8",
+        "orm": "none",
+        "platform": "ngx_php",
+        "webserver": "nginx",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ubiquity-ngx-micro",
+        "notes": "",
+        "versus": "ngx_php"
       }
       }
     }
     }
   ]
   ]

+ 13 - 0
frameworks/PHP/ubiquity/config.toml

@@ -84,6 +84,19 @@ platform = "ngx_php"
 webserver = "nginx"
 webserver = "nginx"
 versus = "ngx_php"
 versus = "ngx_php"
 
 
+[ngx-micro]
+urls.plaintext = "/micro/plaintext"
+urls.json = "/micro/json"
+approach = "Realistic"
+classification = "Micro"
+database = "None"
+database_os = "Linux"
+os = "Linux"
+orm = "none"
+platform = "ngx_php"
+webserver = "nginx"
+versus = "ngx_php"
+
 [workerman]
 [workerman]
 urls.db = "/Db_"
 urls.db = "/Db_"
 urls.query = "/Db_/query/"
 urls.query = "/Db_/query/"

+ 3 - 0
frameworks/PHP/ubiquity/deploy/conf/ngx/services-micro.php

@@ -0,0 +1,3 @@
+<?php
+\Ubiquity\cache\CacheManager::startProd($config);
+\Ubiquity\controllers\Router::start();

+ 53 - 0
frameworks/PHP/ubiquity/ubiquity-ngx-micro.dockerfile

@@ -0,0 +1,53 @@
+FROM ubuntu:20.10
+
+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 > /dev/null
+
+RUN apt-get update -yqq > /dev/null && \
+    apt-get install -yqq wget git unzip libxml2-dev cmake make systemtap-sdt-dev \
+                    zlib1g-dev libpcre3-dev libargon2-0-dev libsodium-dev \
+                    php8.0-cli php8.0-dev libphp8.0-embed nginx > /dev/null
+
+ADD ./ ./
+
+ENV NGINX_VERSION=1.21.0
+
+RUN git clone -b v0.0.25 --single-branch --depth 1 https://github.com/rryqszq4/ngx_php7.git > /dev/null
+
+RUN wget -q http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
+    tar -zxf nginx-${NGINX_VERSION}.tar.gz && \
+    cd nginx-${NGINX_VERSION} && \
+    export PHP_LIB=/usr/lib && \
+    bash ./configure --user=www --group=www \
+            --prefix=/nginx \
+            --with-ld-opt="-Wl,-rpath,$PHP_LIB" \
+            --add-module=/ngx_php7/third_party/ngx_devel_kit \
+            --add-module=/ngx_php7 > /dev/null && \
+    make > /dev/null && make install > /dev/null
+
+RUN apt-get install -yqq composer > /dev/null
+
+RUN composer config -g repo.packagist composer https://packagist.phpcomposer.com
+
+RUN composer require phpmv/ubiquity-ngx:dev-master --quiet
+
+RUN chmod 777 -R app/cache/*
+
+COPY /deploy/conf/ngx/services-micro.php /app/config/ngxServices.php
+
+RUN composer require phpmv/ubiquity-devtools:dev-master --quiet
+
+RUN ./vendor/bin/Ubiquity bootstrap prod
+
+RUN echo "opcache.preload=/app/config/preloader.script.php" >> /deploy/conf/php.ini
+RUN echo "opcache.jit_buffer_size=128M\nopcache.jit=tracing\n" >> /deploy/conf/php.ini
+
+RUN export WORKERS=$(( 4 * $(nproc) )) && \
+    sed -i "s|worker_processes  auto|worker_processes $WORKERS|g" /deploy/conf/ngx/nginx.conf
+
+EXPOSE 8080
+
+CMD /nginx/sbin/nginx -c /deploy/conf/ngx/nginx.conf