Browse Source

[duckphp] Update to PHP8 (#6311)

* [duckphp] Update to PHP8

* Fix for duckphp v1.2.10

* Fix vartiables to int

* Faster array combine in fortunes

* Clean dockerfile
Changed to test a bug
Joan Miquel 4 years ago
parent
commit
b30a82d42c

+ 2 - 2
frameworks/PHP/duckphp/app/Controller/Main.php

@@ -36,7 +36,7 @@ class Main
     }
     }
     public function updates()
     public function updates()
     {
     {
-        $queries = C::GET('queries',1);
+        $queries = (int) C::GET('queries',1);
         $query_count = 1;
         $query_count = 1;
         if ($queries > 1) {
         if ($queries > 1) {
             $query_count = min($queries, 500);
             $query_count = min($queries, 500);
@@ -47,7 +47,7 @@ class Main
     }
     }
     public function queries()
     public function queries()
     {
     {
-        $queries = C::GET('queries',1);
+        $queries = (int) C::GET('queries',1);
         $query_count = 1;
         $query_count = 1;
         if ($queries > 1) {
         if ($queries > 1) {
             $query_count = min($queries, 500);
             $query_count = min($queries, 500);

+ 1 - 1
frameworks/PHP/duckphp/app/Model/FortuneModel.php

@@ -15,7 +15,7 @@ class FortuneModel extends BaseModel
     {
     {
         $sql = 'SELECT id, message FROM fortune';
         $sql = 'SELECT id, message FROM fortune';
         $data = M::DB()->fetchAll($sql);
         $data = M::DB()->fetchAll($sql);
-        $ret = array_combine(array_column($data,'id'),array_column($data,'message'));
+        $ret = array_column($data, 'message', 'id');
         $ret[0] = 'Additional fortune added at request time.';
         $ret[0] = 'Additional fortune added at request time.';
         asort($ret);
         asort($ret);
         return $ret;
         return $ret;

+ 2 - 2
frameworks/PHP/duckphp/app/System/BaseBusiness.php

@@ -6,9 +6,9 @@
 
 
 namespace DuckPhpBenchmark\System;
 namespace DuckPhpBenchmark\System;
 
 
-use DuckPhp\SingletonEx\SingletonEx;
+use DuckPhp\SingletonEx\SingletonExTrait;
 
 
 class BaseBusiness
 class BaseBusiness
 {
 {
-    use SingletonEx;
+    use SingletonExTrait;
 }
 }

+ 2 - 2
frameworks/PHP/duckphp/app/System/BaseModel.php

@@ -6,10 +6,10 @@
 
 
 namespace DuckPhpBenchmark\System;
 namespace DuckPhpBenchmark\System;
 
 
-use DuckPhp\SingletonEx\SingletonEx;
+use DuckPhp\SingletonEx\SingletonExTrait;
 
 
 class BaseModel
 class BaseModel
 {
 {
-    use SingletonEx;
+    use SingletonExTrait;
     // override or add your code here
     // override or add your code here
 }
 }

+ 1 - 2
frameworks/PHP/duckphp/composer.json

@@ -2,8 +2,7 @@
   "name": "dvaknheo/duckphp-benchmark",
   "name": "dvaknheo/duckphp-benchmark",
   "type": "project",
   "type": "project",
 	"require" : {
 	"require" : {
-		"php" : "^7.2",
-		"dvaknheo/duckphp" : "1.2.7"
+		"dvaknheo/duckphp" : "1.2.10"
 	},
 	},
 	"autoload" : {
 	"autoload" : {
 		"psr-4" : {
 		"psr-4" : {

+ 2 - 3
frameworks/PHP/duckphp/deploy/conf/php-fpm.conf

@@ -14,14 +14,13 @@
 ; Pid file
 ; Pid file
 ; Note: the default prefix is /var
 ; Note: the default prefix is /var
 ; Default Value: none
 ; Default Value: none
-pid = /run/php/php7.4-fpm.pid
+pid = /run/php/php-fpm.pid
 
 
 ; Error log file
 ; Error log file
 ; If it's set to "syslog", log is sent to syslogd instead of being written
 ; If it's set to "syslog", log is sent to syslogd instead of being written
 ; into a local file.
 ; into a local file.
 ; Note: the default prefix is /var
 ; Note: the default prefix is /var
 ; Default Value: log/php-fpm.log
 ; Default Value: log/php-fpm.log
-;error_log = /var/log/php7.4-fpm.log
 error_log = /dev/stderr
 error_log = /dev/stderr
 
 
 
 
@@ -161,7 +160,7 @@ group = www-data
 ;                            (IPv6 and IPv4-mapped) on a specific port;
 ;                            (IPv6 and IPv4-mapped) on a specific port;
 ;   '/path/to/unix/socket' - to listen on a unix socket.
 ;   '/path/to/unix/socket' - to listen on a unix socket.
 ; Note: This value is mandatory.
 ; Note: This value is mandatory.
-listen = /var/run/php/php7.4-fpm.sock
+listen = /var/run/php/php-fpm.sock
 
 
 ; Set listen(2) backlog.
 ; Set listen(2) backlog.
 ; Default Value: 511 (-1 on FreeBSD and OpenBSD)
 ; Default Value: 511 (-1 on FreeBSD and OpenBSD)

+ 2 - 1
frameworks/PHP/duckphp/deploy/nginx.conf

@@ -2,6 +2,7 @@ user www-data;
 worker_processes  auto;
 worker_processes  auto;
 error_log stderr error;
 error_log stderr error;
 worker_rlimit_nofile 200000;
 worker_rlimit_nofile 200000;
+daemon off;
 
 
 events {
 events {
     worker_connections 16384;
     worker_connections 16384;
@@ -40,7 +41,7 @@ http {
 
 
 
 
     upstream fastcgi_backend {
     upstream fastcgi_backend {
-        server unix:/var/run/php/php7.4-fpm.sock;
+        server unix:/var/run/php/php-fpm.sock;
         keepalive 50;
         keepalive 50;
     }
     }
 
 

+ 7 - 8
frameworks/PHP/duckphp/duckphp.dockerfile

@@ -1,24 +1,23 @@
-FROM ubuntu:20.04
+FROM ubuntu:20.10
 
 
 ARG DEBIAN_FRONTEND=noninteractive
 ARG DEBIAN_FRONTEND=noninteractive
 
 
 RUN apt-get update -yqq && apt-get install -yqq software-properties-common > /dev/null
 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 LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 RUN apt-get update -yqq > /dev/null && \
 RUN apt-get update -yqq > /dev/null && \
-    apt-get install -yqq nginx git unzip php7.4 php7.4-common php7.4-cli php7.4-fpm php7.4-mysql  > /dev/null
+    apt-get install -yqq nginx git unzip \
+    php8.0-cli php8.0-fpm php8.0-mysql  > /dev/null
 
 
 RUN apt-get install -yqq composer > /dev/null
 RUN apt-get install -yqq composer > /dev/null
 
 
-COPY deploy/conf/* /etc/php/7.4/fpm/
+COPY deploy/conf/* /etc/php/8.0/fpm/
 
 
 ADD ./ /duckphp
 ADD ./ /duckphp
 WORKDIR /duckphp
 WORKDIR /duckphp
 
 
-RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/7.4/fpm/php-fpm.conf ; fi;
+RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/8.0/fpm/php-fpm.conf ; fi;
 
 
 RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
 RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
 
 
-EXPOSE 8080
-
-CMD service php7.4-fpm start && \
-    nginx -c /duckphp/deploy/nginx.conf -g "daemon off;"
+CMD service php8.0-fpm start && \
+    nginx -c /duckphp/deploy/nginx.conf