Browse Source

[ngx_php] Add fortune async (#5138)

* Set 'php_keepalive' 200

* [ngx_php] Add fortune async

* [ngx_php] Fixed fortune async

* [ngx_php] Set php_keepalive to 200

* [ngx)_php] Move const and mysql-driver into app-async.php
rryqszq4 5 years ago
parent
commit
1a2e261ce5

+ 34 - 1
frameworks/PHP/php-ngx/app-async.php

@@ -1,2 +1,35 @@
 <?php
-// Future app to use Mysql async pool 
+// Future app to use Mysql async pool 
+
+require_once "/ngx_php7/t/lib/mysql.php";
+define("DB_HOST", gethostbyname("tfb-database"));
+define("DB_PORT", "3306");
+define("DB_USER", "benchmarkdbuser");
+define("DB_PASS", "benchmarkdbpass");
+define("DB_NAME", "hello_world");
+
+function fortune()
+{
+    $my = new php\ngx\mysql();
+    yield from $my->connect(DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME);
+    $ret = yield from $my->query("SELECT id, message FROM Fortune");
+    
+    $arr = [];
+    foreach ($ret as $row) {
+            $arr[$row["id"]] = $row["message"];
+    }
+    $arr[0] = "Additional fortune added at request time.";
+    asort($arr);
+    
+    $html = "";
+    foreach ($arr as $id => $message) {
+        $message = htmlspecialchars($message, ENT_QUOTES, "UTF-8");
+        $html .= "<tr><td>$id</td><td>$message</td></tr>";
+    }
+
+    echo    "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>",
+            $html,
+            "</table></body></html>";
+
+    yield from $my->close();
+}

+ 18 - 0
frameworks/PHP/php-ngx/benchmark_config.json

@@ -44,6 +44,24 @@
       "display_name": "PHP-raw-ngx-Postgres",
       "notes": "ngx_php Postgres",
       "versus": "php"
+    },
+    "async": {
+      "fortune_url": "/fortune",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MySQL",
+      "framework": "None",
+      "language": "PHP",
+      "flavor": "PHP7",
+      "orm": "Raw",
+      "platform": "ngx_php",
+      "webserver": "nginx",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "PHP-raw-ngx-async",
+      "notes": "ngx_php async",
+      "versus": "php"
     }
   }]
 }

+ 1 - 1
frameworks/PHP/php-ngx/deploy/nginx.conf

@@ -34,7 +34,7 @@ http {
         root /;
         index  index.html;
 
-        php_keepalive 100;
+        php_keepalive 200;
 
         location = /hello {
             add_header Content-Type text/plain;

+ 61 - 0
frameworks/PHP/php-ngx/deploy/nginx_async.conf

@@ -0,0 +1,61 @@
+user www-data;
+worker_processes  auto;
+error_log stderr error;
+#worker_rlimit_nofile 100000;
+#timer_resolution 1000ms;
+daemon off;
+
+events {
+    worker_connections 65536;
+	multi_accept off;	 
+}
+
+http {
+    include       /etc/nginx/mime.types;
+    access_log off;
+    server_tokens off;
+
+    sendfile off;
+    tcp_nopush off;
+    tcp_nodelay on;
+    keepalive_timeout 65s;
+    keepalive_disable none;
+    keepalive_requests 10000;
+
+    php_ini_path /deploy/conf/php.ini;
+
+    init_worker_by_php '
+        require "app-async.php";
+    ';
+
+    server {
+        listen       8080 default_server reuseport;
+
+        root /;
+        index  index.html;
+
+        php_keepalive 200;
+
+        location = /hello {
+            add_header Content-Type text/plain;
+            content_by_php '
+                echo "Hello, World!";
+            ';
+        }
+
+        location = /json {
+            add_header Content-Type application/json;
+            content_by_php '
+                echo json_encode(["message" => "Hello, World!"]);
+            ';
+        }
+        
+        location = /fortune {
+            add_header Content-Type "text/html; charset=UTF-8";
+	        content_by_php '
+                yield from fortune();
+            ';
+        }
+
+    }
+}

+ 1 - 1
frameworks/PHP/php-ngx/deploy/nginx_plain_php.conf

@@ -35,7 +35,7 @@ http {
         root /;
         index  index.html;
 
-        php_keepalive 100;
+        php_keepalive 200;
 
         location = /hello {
             add_header Content-Type text/plain;

+ 31 - 0
frameworks/PHP/php-ngx/php-ngx-async.dockerfile

@@ -0,0 +1,31 @@
+FROM ubuntu:19.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.3 php7.3-common php7.3-dev libphp7.3-embed php7.3-mysql nginx > /dev/null
+
+ADD ./ ./
+
+ENV NGINX_VERSION=1.17.3
+
+RUN git clone -b v0.0.19 --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 --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
+
+CMD /nginx/sbin/nginx -c /deploy/nginx_async.conf
+
+