Browse Source

[Ubiquity] add ngx platform (#6042)

* add ngx files

* add composer

* fix composer typo

* init_worker_by_php_block usage

* try to fix composer autoloading pb

* Update _ngx.php

* Update _ngx.php

* Update _ngx.php

* fix dir pb

* fix composer pb

* add Db

* add other db urls

* add preloading

* add ngx_php in README

* rename nginx www user

* versus ngx_php
J-C HERON 4 years ago
parent
commit
c200836a40

+ 16 - 0
frameworks/PHP/ubiquity/.ubiquity/_ngx.php

@@ -0,0 +1,16 @@
+<?php
+use Ubiquity\servers\ngx\NgxServer;
+
+if (! defined('DS')) {
+	define('DS', DIRECTORY_SEPARATOR);
+	define('ROOT', __DIR__ . \DS . '..' . \DS . 'app' . \DS);
+}
+$config = include ROOT . 'config/config.php';
+$config["siteUrl"] = 'http://0.0.0.0:8080';
+require ROOT . './../vendor/autoload.php';
+NgxServer::init($config);
+require ROOT . 'config/ngxServices.php';
+
+function handleRequest() {
+	NgxServer::handleRequest();
+}

+ 4 - 16
frameworks/PHP/ubiquity/README.md

@@ -5,7 +5,7 @@ Ubiquity is a full-stack php framework, These tests involve:
 - the ORM part (Full)
 - the JSON serialization (native php)
 
-Tests are available with NginX server, Swoole Roadrunner and Workerman platforms.
+Tests are available with NginX server, Swoole ,Roadrunner, ngx_php and Workerman platforms.
 
 ## Test Type Implementation Source Code
 The tests are separated into controllers:
@@ -23,7 +23,7 @@ The tests are separated into controllers:
 - `Plaintext` for plaintext response
   * [PLAINTEXT](app/controllers/Plaintext.php)
 
-### Ubiquity with async platforms (Swoole, Workerman or Roadrunner) + Pgsql
+### Ubiquity with async platforms (Swoole, Workerman, ngx_php or Roadrunner) + Pgsql
 - `Db_` for database access with ORM (PDO Pgsql)
   * [DB](app/controllers/Db_.php)
   * [QUERY](app/controllers/Db_.php)
@@ -32,25 +32,12 @@ The tests are separated into controllers:
 - `Fortunes_` for using the internal template engine
   * [FORTUNES](app/controllers/Fortunes_.php)
 
-### Ubiquity with async platforms (Swoole, Workerman or Roadrunner)
+### Ubiquity with async platforms (Swoole, Workerman, ngx_php or Roadrunner)
 - `Json_` for JSON response
   * [JSON](app/controllers/Json_.php)
 - `Plaintext_` for plaintext response
   * [PLAINTEXT](app/controllers/Plaintext_.php)
 
-### Ubiquity + PDO Mysql
-- `Json` for JSON response
-  * [JSON](app/controllers/Json.php)
-- `Db` for database access with ORM (PDO Mysql)
-  * [DB](app/controllers/Db.php)
-  * [QUERY](app/controllers/Db.php)
-  * [CACHED QUERY (not implemented)]()
-  * [UPDATE](app/controllers/Db.php) Utilizes transactions
-- `Fortunes` for using the internal template engine
-  * [FORTUNES](app/controllers/Fortunes.php)
-- `Plaintext` for plaintext response
-  * [PLAINTEXT](app/controllers/Plaintext.php)
-
 ### Ubiquity Workerman + MongoDb
 - `DbMongo` for database access
   * [DB](app/controllers/DbMongo.php)
@@ -68,6 +55,7 @@ The tests were run with:
 * [Swoole](https://www.swoole.com/), [Ubiquity-swoole](https://github.com/phpMv/ubiquity-swoole)
 * [Workerman](https://github.com/walkor/Workerman), [Ubiquity-workerman](https://github.com/phpMv/ubiquity-workerman)
 * [Roadrunner](https://github.com/spiral/roadrunner), [Roadrunner-ubiquity](https://github.com/Lapinskas/roadrunner-ubiquity)
+* [ngx_php7](https://github.com/rryqszq4/ngx_php7), [ubiquity-ngx](https://github.com/phpmv/ubiquity-ngx)
 * [MySQL 8.0](https://dev.mysql.com/)
 * [MongoDb 4.2](https://www.mongodb.com/)
 

+ 23 - 0
frameworks/PHP/ubiquity/benchmark_config.json

@@ -178,6 +178,29 @@
         "display_name": "ubiquity-workerman-mongo",
         "notes": "",
         "versus": "php"
+      },
+      "ngx": {
+        "json_url": "/Json_",
+        "plaintext_url": "/Plaintext_",
+        "db_url": "/Db_",
+        "query_url": "/Db_/query/",
+        "fortune_url": "/Fortunes_",
+        "update_url": "/Db_/update/",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "Postgres",
+        "framework": "Ubiquity",
+        "language": "PHP",
+        "flavor": "PHP7",
+        "orm": "Full",
+        "platform": "ngx_php",
+        "webserver": "nginx",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ubiquity-ngx",
+        "notes": "",
+        "versus": "ngx_php"
       }
     }
   ]

+ 47 - 0
frameworks/PHP/ubiquity/deploy/conf/ngx/nginx.conf

@@ -0,0 +1,47 @@
+user www-data;
+worker_cpu_affinity auto;
+worker_processes  auto;
+error_log stderr error;
+#worker_rlimit_nofile 1024000;
+timer_resolution 1s;
+daemon off;
+pcre_jit on;
+
+events {
+    worker_connections 100000;
+	multi_accept off;	 
+}
+
+http {
+    #include       /etc/nginx/mime.types;
+    access_log off;
+    server_tokens off;
+    msie_padding off;
+
+    sendfile off;
+    tcp_nopush off;
+    tcp_nodelay on;
+    keepalive_timeout 65s;
+    keepalive_disable none;
+    keepalive_requests 100000;
+
+    php_ini_path /deploy/conf/php.ini;
+
+    init_worker_by_php '
+        require "/.ubiquity/_ngx.php";
+    ';
+
+    server {
+        listen       *:8080 backlog=65535 reuseport;
+
+        root /;
+
+        php_keepalive 256;
+
+        location / {
+            content_by_php '
+                handleRequest();
+            ';
+        }
+    }
+}

+ 17 - 0
frameworks/PHP/ubiquity/deploy/conf/ngx/pgsql/ngxServices.php

@@ -0,0 +1,17 @@
+<?php
+\Ubiquity\cache\CacheManager::startProd($config);
+\Ubiquity\orm\DAO::setModelsDatabases([
+	'models\\Fortune' => 'pgsql',
+	'models\\World' => 'pgsql'
+]);
+
+\Ubiquity\cache\CacheManager::warmUpControllers([
+	\controllers\Plaintext_::class,
+	\controllers\Json_::class,
+	\controllers\Db_::class,
+	\controllers\Fortunes_::class
+]);
+
+\Ubiquity\orm\DAO::startDatabase($config, 'pgsql');
+\controllers\Db_::warmup();
+\controllers\Fortunes_::warmup();

+ 46 - 0
frameworks/PHP/ubiquity/ubiquity-ngx.dockerfile

@@ -0,0 +1,46 @@
+FROM ubuntu:20.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 > /dev/null
+RUN apt-get update -yqq > /dev/null && \
+    apt-get install -yqq wget git unzip libxml2-dev cmake make systemtap-sdt-dev \
+                    zlibc zlib1g zlib1g-dev libpcre3 libpcre3-dev libargon2-0-dev libsodium-dev \
+                    php7.4 php7.4-common php7.4-dev libphp7.4-embed php7.4-pgsql nginx > /dev/null
+
+ADD ./ ./
+
+ENV NGINX_VERSION=1.19.2
+
+RUN git clone -b v0.0.24 --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 && \ 
+    ./configure --user=www-data --group=www-data \
+            --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 composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
+
+RUN chmod 777 -R app/cache/*
+
+COPY /deploy/conf/ngx/pgsql/ngxServices.php /app/config/ngxServices.php
+
+RUN echo "opcache.preload=/app/config/preloader.script.php" >> /deploy/conf/php.ini
+
+RUN export WORKERS=$(( 4 * $(nproc) )) && \
+    sed -i "s|worker_processes  auto|worker_processes $WORKERS|g" /deploy/conf/ngx/nginx.conf
+
+CMD /nginx/sbin/nginx -c /deploy/conf/ngx/nginx.conf