Browse Source

[php] Fix Cakephp & Adapterman (#7654)

* [php] Fix Cakephp

* Update to Ubuntu 22.04

* Update versions

* Add Adapterman
Joan Miquel 2 years ago
parent
commit
3bca4981a9

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

@@ -23,6 +23,29 @@
             "display_name": "CakePHP",
             "notes": "",
             "versus": "php"
+        },
+        "workerman": {
+            "json_url": "/json",
+            "db_url": "/db",
+            "query_url": "/queries?queries=",
+            "fortune_url": "/fortunes",
+            "plaintext_url": "/plaintext",
+            "update_url": "/updates?queries=",
+            "port": 8080,
+            "approach": "Realistic",
+            "classification": "Fullstack",
+            "database": "MySQL",
+            "framework": "cakephp",
+            "language": "PHP",
+            "flavor": "PHP8.1",
+            "orm": "Full",
+            "platform": "FPM/FastCGI",
+            "webserver": "nginx",
+            "os": "Linux",
+            "database_os": "Linux",
+            "display_name": "CakePHP",
+            "notes": "",
+            "versus": "php"
         }
     }]
 }

+ 30 - 0
frameworks/PHP/cakephp/cakephp-workerman.dockerfile

@@ -0,0 +1,30 @@
+FROM ubuntu:22.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 && \
+    apt-get update -yqq > /dev/null && apt-get upgrade -yqq > /dev/null
+
+RUN apt-get install -yqq git unzip \
+    php8.1-cli php8.1-mysql php8.1-mbstring php8.1-intl php8.1-xml php8.1-curl > /dev/null
+
+COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
+
+RUN apt-get install -y php-pear php8.1-dev libevent-dev > /dev/null
+RUN pecl install event-3.0.8 > /dev/null && echo "extension=event.so" > /etc/php/8.1/cli/conf.d/event.ini
+
+EXPOSE 8080
+
+ADD ./ /cakephp
+WORKDIR /cakephp
+
+RUN composer install --optimize-autoloader --classmap-authoritative --no-dev  --quiet
+RUN composer require joanhey/adapterman:^0.5
+
+RUN chmod -R 777 /cakephp
+
+#COPY deploy/conf/cli-php.ini /etc/php/8.1/cli/php.ini
+
+CMD php -c deploy/conf/cli-php.ini \
+    server.php start

+ 6 - 5
frameworks/PHP/cakephp/cakephp.dockerfile

@@ -1,12 +1,13 @@
-FROM ubuntu:20.04
+FROM ubuntu:22.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
-RUN apt-get update -yqq > /dev/null && \
-    apt-get install -yqq nginx git unzip \
-    php8.1-fpm php8.1-mysql php8.1-xml php8.1-mbstring php8.1-intl php8.1-dev > /dev/null
+RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php > /dev/null && \
+    apt-get update -yqq > /dev/null && apt-get upgrade -yqq > /dev/null
+
+RUN apt-get install -yqq nginx git unzip \
+    php8.1-fpm php8.1-mysql php8.1-xml php8.1-mbstring php8.1-intl php8.1-dev  php8.1-curl > /dev/null
 
 COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
 

+ 6 - 3
frameworks/PHP/cakephp/composer.json

@@ -5,8 +5,8 @@
     "type": "project",
     "license": "MIT",
     "require": {
-        "cakephp/cakephp": "^4.3",
-        "cakephp/plugin-installer": "^1.0"
+        "cakephp/cakephp": "^4.4",
+        "cakephp/plugin-installer": "^1.3"
     },
     "autoload": {
         "psr-4": {
@@ -25,6 +25,9 @@
         "test": "phpunit --colors=always"
     },
     "config": {
-        "sort-packages": true
+        "sort-packages": true,
+        "allow-plugins": {
+            "*": true
+        }
     }
 }

+ 1 - 1
frameworks/PHP/cakephp/config/app.php

@@ -44,7 +44,7 @@ return [
         'encoding' => env('APP_ENCODING', 'UTF-8'),
         'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'),
         'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'),
-        'base' => false,
+        'base' => dirname(__DIR__),
         'dir' => 'src',
         'webroot' => 'webroot',
         'wwwRoot' => WWW_ROOT,

+ 16 - 0
frameworks/PHP/cakephp/deploy/conf/cli-php.ini

@@ -0,0 +1,16 @@
+#zend_extension=opcache.so
+opcache.enable=1
+opcache.enable_cli=1
+opcache.validate_timestamps=0
+opcache.save_comments=0
+opcache.enable_file_override=1
+opcache.huge_code_pages=1
+
+mysqlnd.collect_statistics = Off
+
+memory_limit = 512M
+
+opcache.jit_buffer_size = 128M
+opcache.jit = tracing
+
+disable_functions=header,header_remove,http_response_code,setcookie,session_create_id,session_id,session_name,session_save_path,session_status,session_start,session_write_close,session_regenerate_id,set_time_limit

+ 45 - 0
frameworks/PHP/cakephp/server.php

@@ -0,0 +1,45 @@
+<?php
+require_once __DIR__.'/vendor/autoload.php';
+
+use Adapterman\Adapterman;
+use Workerman\Lib\Timer;
+use Workerman\Worker;
+
+Adapterman::init();
+
+$http_worker        = new Worker('http://0.0.0.0:8080');
+$http_worker->count = (int) shell_exec('nproc') * 4;
+$http_worker->name  = 'AdapterMan-CakePHP';
+
+$http_worker->onWorkerStart = function () {
+    HeaderDate::init();
+    //init();
+    require __DIR__.'/start.php';
+};
+
+$http_worker->onMessage = static function ($connection, $request) {
+
+    $connection->send(run());
+};
+
+Worker::runAll();
+
+class HeaderDate
+{
+    const NAME = 'Date: ';
+
+    /**
+     * Date header
+     *
+     * @var string
+     */
+    public static $date;
+
+    public static function init(): void
+    {
+        self::$date = self::NAME.gmdate('D, d M Y H:i:s').' GMT';
+        Timer::add(1, static function () {
+            self::$date = self::NAME.gmdate('D, d M Y H:i:s').' GMT';
+        });
+    }
+}

+ 45 - 0
frameworks/PHP/cakephp/start.php

@@ -0,0 +1,45 @@
+<?php
+/**
+ * The Front Controller for handling every request
+ *
+ * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ * @link          https://cakephp.org CakePHP(tm) Project
+ * @since         0.2.9
+ * @license       MIT License (https://opensource.org/licenses/mit-license.php)
+ */
+
+
+require __DIR__ . '/vendor/autoload.php';
+
+use App\Application;
+use Cake\Http\Server;
+
+class_alias(
+    'Cake\Error\ConsoleErrorHandler',
+    'Cake\Console\ConsoleErrorHandler'
+);
+
+global $server;
+
+// Bind your application to the server.
+$server = new Server(new Application(__DIR__ . '/config'));
+
+
+function run(): string
+{
+    global $server;
+    ob_start();
+
+    // Run the request/response through the application and emit the response.
+    $server->emit($server->run());
+    header(HeaderDate::$date); // To pass the bench, nginx auto add it
+
+    return ob_get_clean();
+}