Browse Source

Add Ubiquity-react (#4753)

jcheron 6 years ago
parent
commit
ac89c8e5dc

+ 17 - 0
frameworks/PHP/ubiquity/.ubiquity/_react.php

@@ -0,0 +1,17 @@
+#!/usr/bin/env php
+<?php
+// react.php
+
+if (! defined ( 'DS' )) {
+	define ( 'DS', DIRECTORY_SEPARATOR );
+	define ( 'ROOT', __DIR__ . \DS .'..'.\DS. 'app' . \DS );
+}
+$config=include ROOT.'config/config.php';
+$sConfig= include __DIR__.\DS.'react-config.php';
+$address=$sConfig['host'].':'.$sConfig['port'];
+$config ["siteUrl"] = 'http://'.$address;
+require ROOT . './../vendor/autoload.php';
+require ROOT.'config/services.php';
+$reactServer=new \Ubiquity\servers\react\ReactServer();
+$reactServer->init($config, __DIR__);
+$reactServer->run($address);

+ 2 - 0
frameworks/PHP/ubiquity/.ubiquity/react-config.php

@@ -0,0 +1,2 @@
+<?php
+return array("host"=>"0.0.0.0","port"=>8085);

+ 5 - 2
frameworks/PHP/ubiquity/README.md

@@ -5,6 +5,8 @@ Ubiquity is a full-stack php framework, These tests involve:
 - the ORM part (Full)
 - the ORM part (Full)
 - the JSON serialization (native php)
 - the JSON serialization (native php)
 
 
+Tests are available with NginX and Ubiquity-React servers.
+
 ## Test Type Implementation Source Code
 ## Test Type Implementation Source Code
 The tests are separated into 4 controllers:
 The tests are separated into 4 controllers:
 - `Json` for JSON response
 - `Json` for JSON response
@@ -14,7 +16,7 @@ The tests are separated into 4 controllers:
   * [QUERY](app/controllers/Db.php)
   * [QUERY](app/controllers/Db.php)
   * [CACHED QUERY (not implemented)]()
   * [CACHED QUERY (not implemented)]()
   * [UPDATE](app/controllers/Db.php)
   * [UPDATE](app/controllers/Db.php)
-- `Fortunes` for using the Twig template engine
+- `Fortunes` for using the internal template engine
   * [FORTUNES](app/controllers/Fortunes.php)
   * [FORTUNES](app/controllers/Fortunes.php)
 - `Plaintext` for plaintext response
 - `Plaintext` for plaintext response
   * [PLAINTEXT](app/controllers/Plaintext.php)
   * [PLAINTEXT](app/controllers/Plaintext.php)
@@ -22,9 +24,10 @@ The tests are separated into 4 controllers:
 
 
 ## Important Libraries
 ## Important Libraries
 The tests were run with:
 The tests were run with:
-* [Ubiquity 2.1.2](https://ubiquity.kobject.net/)
+* [Ubiquity 2.1.*](https://ubiquity.kobject.net/)
 * [PHP Version 7.3.*](http://www.php.net/) with FPM and APC
 * [PHP Version 7.3.*](http://www.php.net/) with FPM and APC
 * [nginx 1.14](http://nginx.org/)
 * [nginx 1.14](http://nginx.org/)
+* [Ubiquity-reactphp server](https://github.com/phpMv/ubiquity-reactphp)
 * [MySQL 5.7](https://dev.mysql.com/)
 * [MySQL 5.7](https://dev.mysql.com/)
 
 
 ## Test URLs
 ## Test URLs

+ 1 - 0
frameworks/PHP/ubiquity/app/config/services.php

@@ -1,2 +1,3 @@
 <?php
 <?php
 \Ubiquity\cache\CacheManager::startProd($config);
 \Ubiquity\cache\CacheManager::startProd($config);
+\Ubiquity\orm\DAO::startDatabase($config);

+ 2 - 0
frameworks/PHP/ubiquity/app/config/services_.php

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

+ 3 - 3
frameworks/PHP/ubiquity/app/controllers/Db.php

@@ -5,15 +5,15 @@ use Ubiquity\controllers\Controller;
 use Ubiquity\orm\DAO;
 use Ubiquity\orm\DAO;
 use models\World;
 use models\World;
 use Ubiquity\controllers\Startup;
 use Ubiquity\controllers\Startup;
+use Ubiquity\utils\http\UResponse;
+
 
 
 /**
 /**
  * Bench controller.
  * Bench controller.
  **/
  **/
 class Db extends Controller{
 class Db extends Controller{
 	public function initialize(){
 	public function initialize(){
-		\header( 'Content-Type: application/json;charset=utf-8' );
-		$config=Startup::getConfig();
-		\Ubiquity\orm\DAO::startDatabase($config);
+		UResponse::setContentType( 'application/json' );
 	}
 	}
 
 
 	public function index() {
 	public function index() {

+ 17 - 0
frameworks/PHP/ubiquity/app/controllers/Db_.php

@@ -0,0 +1,17 @@
+<?php
+namespace controllers;
+
+use Ubiquity\controllers\Startup;
+use Ubiquity\utils\http\UResponse;
+
+
+/**
+ * Bench controller.
+ **/
+class Db_ extends Db{
+	public function initialize(){
+		UResponse::setContentType( 'application/json' );
+		$config=Startup::getConfig();
+		\Ubiquity\orm\DAO::startDatabase($config);
+	}
+}

+ 0 - 2
frameworks/PHP/ubiquity/app/controllers/Fortunes.php

@@ -11,8 +11,6 @@ use models\Fortune;
 class Fortunes extends Controller {
 class Fortunes extends Controller {
 	public function initialize(){
 	public function initialize(){
 		Startup::$templateEngine=new MicroTemplateEngine();
 		Startup::$templateEngine=new MicroTemplateEngine();
-		$config=Startup::getConfig();
-		\Ubiquity\orm\DAO::startDatabase($config);
 	}
 	}
 	
 	
 	public function index() {
 	public function index() {

+ 15 - 0
frameworks/PHP/ubiquity/app/controllers/Fortunes_.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace controllers;
+
+use Ubiquity\controllers\Startup;
+use Ubiquity\views\engine\micro\MicroTemplateEngine;
+
+class Fortunes_ extends Fortunes {
+	public function initialize(){
+		Startup::$templateEngine=new MicroTemplateEngine();
+		$config=Startup::getConfig();
+		\Ubiquity\orm\DAO::startDatabase($config);
+	}
+}
+

+ 2 - 1
frameworks/PHP/ubiquity/app/controllers/Json.php

@@ -2,13 +2,14 @@
 namespace controllers;
 namespace controllers;
 
 
 use Ubiquity\controllers\Controller;
 use Ubiquity\controllers\Controller;
+use Ubiquity\utils\http\UResponse;
 
 
 /**
 /**
  * Json controller.
  * Json controller.
  **/
  **/
 class Json extends Controller{
 class Json extends Controller{
 	public function initialize() {
 	public function initialize() {
-		\header( 'Content-Type: application/json;charset=utf-8' );
+		UResponse::setContentType( 'application/json' );
 	}
 	}
 	public function index(){
 	public function index(){
 		echo \json_encode(['message' => 'Hello, World!']);
 		echo \json_encode(['message' => 'Hello, World!']);

+ 2 - 1
frameworks/PHP/ubiquity/app/controllers/Plaintext.php

@@ -2,6 +2,7 @@
 namespace controllers;
 namespace controllers;
 
 
 use Ubiquity\controllers\Controller;
 use Ubiquity\controllers\Controller;
+use Ubiquity\utils\http\UResponse;
 
 
 /**
 /**
  * Plaintext controller.
  * Plaintext controller.
@@ -9,7 +10,7 @@ use Ubiquity\controllers\Controller;
 class Plaintext extends Controller{
 class Plaintext extends Controller{
 	
 	
 	public function initialize(){
 	public function initialize(){
-		\header("Content-Type: text/plain");
+		UResponse::setContentType('text/plain; charset=utf-8');
 	}
 	}
 	public function index() {
 	public function index() {
 		echo "Hello, World!";
 		echo "Hello, World!";

+ 26 - 3
frameworks/PHP/ubiquity/benchmark_config.json

@@ -3,13 +3,36 @@
   "tests": [
   "tests": [
     {
     {
       "default": {
       "default": {
+        "json_url": "/Json",
+        "plaintext_url": "/Plaintext",
+        "db_url": "/Db_",
+        "update_url": "/Db_/update/",
+        "query_url": "/Db_/query/",
+        "fortune_url": "/Fortunes_",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "MySQL",
+        "framework": "ubiquity",
+        "language": "PHP",
+        "flavor": "PHP7",
+        "orm": "Full",
+        "platform": "None",
+        "webserver": "nginx",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ubiquity",
+        "notes": "",
+        "versus": "php"
+      },
+      "react": {
         "json_url": "/Json",
         "json_url": "/Json",
         "plaintext_url": "/Plaintext",
         "plaintext_url": "/Plaintext",
         "db_url": "/Db",
         "db_url": "/Db",
         "update_url": "/Db/update/",
         "update_url": "/Db/update/",
         "query_url": "/Db/query/",
         "query_url": "/Db/query/",
         "fortune_url": "/Fortunes",
         "fortune_url": "/Fortunes",
-        "port": 8080,
+        "port": 8085,
         "approach": "Realistic",
         "approach": "Realistic",
         "classification": "Fullstack",
         "classification": "Fullstack",
         "database": "MySQL",
         "database": "MySQL",
@@ -18,10 +41,10 @@
         "flavor": "PHP7",
         "flavor": "PHP7",
         "orm": "Full",
         "orm": "Full",
         "platform": "None",
         "platform": "None",
-        "webserver": "nginx",
+        "webserver": "react",
         "os": "Linux",
         "os": "Linux",
         "database_os": "Linux",
         "database_os": "Linux",
-        "display_name": "ubiquity",
+        "display_name": "ubiquity-react",
         "notes": "",
         "notes": "",
         "versus": "php"
         "versus": "php"
       }
       }

+ 2 - 0
frameworks/PHP/ubiquity/deploy/conf/php-cli.ini

@@ -0,0 +1,2 @@
+# Enable OPcache also for CLI scripts
+opcache.enable_cli = On

+ 5 - 6
frameworks/PHP/ubiquity/deploy/nginx.conf

@@ -22,11 +22,10 @@ http {
     keepalive_disable none;
     keepalive_disable none;
     keepalive_requests 10000;
     keepalive_requests 10000;
 
 
-    #the bench don't use any static file
-    #open_file_cache max=2000 inactive=20s;
-    #open_file_cache_valid 60s;
-    #open_file_cache_min_uses 5;
-    #open_file_cache_errors off;
+    open_file_cache max=2000 inactive=20s;
+    open_file_cache_valid 60s;
+    open_file_cache_min_uses 5;
+    open_file_cache_errors off;
 
 
   #FastCGI optimizations
   #FastCGI optimizations
     fastcgi_buffers 256 16k;
     fastcgi_buffers 256 16k;
@@ -42,7 +41,7 @@ http {
 
 
     upstream fastcgi_backend {
     upstream fastcgi_backend {
         server unix:/var/run/php/php7.3-fpm.sock;
         server unix:/var/run/php/php7.3-fpm.sock;
-        keepalive 40;
+        keepalive 50;
     }
     }
 
 
     server {
     server {

+ 1 - 1
frameworks/PHP/ubiquity/index.php

@@ -5,5 +5,5 @@ define('DS', DIRECTORY_SEPARATOR);
 define('ROOT', __DIR__.DS.'app'.DS);
 define('ROOT', __DIR__.DS.'app'.DS);
 $config=include_once ROOT.'config/config.php';
 $config=include_once ROOT.'config/config.php';
 require_once ROOT.'./../vendor/autoload.php';
 require_once ROOT.'./../vendor/autoload.php';
-require_once ROOT.'config/services.php';
+require_once ROOT.'config/services_.php';
 \Ubiquity\controllers\Startup::run($config);
 \Ubiquity\controllers\Startup::run($config);

+ 25 - 0
frameworks/PHP/ubiquity/ubiquity-react.dockerfile

@@ -0,0 +1,25 @@
+FROM ubuntu:18.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
+RUN apt-get update -yqq > /dev/null && \
+    apt-get install -yqq git unzip php7.3 php7.3-common php7.3-cli php7.3-mysql php7.3-mbstring > /dev/null
+
+RUN apt-get install -yqq composer > /dev/null
+
+COPY deploy/conf/php-cli.ini /etc/php/7.3/cli/conf.d/php.ini
+
+ADD ./ /ubiquity
+WORKDIR /ubiquity
+
+RUN composer require phpmv/ubiquity-devtools:dev-master phpmv/ubiquity-reactphp:dev-master --quiet
+
+RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
+
+RUN chmod 777 -R /ubiquity/app/cache/*
+
+RUN chmod 777 -R /ubiquity/.ubiquity/*
+
+CMD /ubiquity/vendor/bin/Ubiquity serve -t=react -p=8085 -h=0.0.0.0