diff --git a/frameworks/PHP/php/benchmark_config.json b/frameworks/PHP/php/benchmark_config.json index 597a4f83452..e91e5e74fc8 100644 --- a/frameworks/PHP/php/benchmark_config.json +++ b/frameworks/PHP/php/benchmark_config.json @@ -183,6 +183,29 @@ "notes": "", "versus": "php" }, + "workerman": { + "json_url": "/json.php", + "plaintext_url": "/plaintext.php", + "db_url": "/dbraw.php", + "query_url": "/dbquery.php?queries=", + "fortune_url": "/fortune.php", + "update_url": "/updateraw.php?queries=", + "port": 8080, + "approach": "Realistic", + "classification": "Platform", + "database": "MySQL", + "framework": "PHP", + "language": "PHP", + "flavor": "PHP8", + "orm": "Raw", + "platform": "Workerman", + "webserver": "none", + "os": "Linux", + "database_os": "Linux", + "display_name": "php-workerman", + "notes": "Workerman without worker mode", + "versus": "php" + }, "eloquent": { "db_url": "/eloquent/db-eloquent.php", "query_url": "/eloquent/db-eloquent.php?queries=", diff --git a/frameworks/PHP/php/deploy/workerman/cli-php.ini b/frameworks/PHP/php/deploy/workerman/cli-php.ini new file mode 100644 index 00000000000..26d9ec62331 --- /dev/null +++ b/frameworks/PHP/php/deploy/workerman/cli-php.ini @@ -0,0 +1,16 @@ +opcache.enable=1 +opcache.enable_cli=1 +opcache.validate_timestamps=0 +opcache.save_comments=0 +opcache.enable_file_override=1 +opcache.memory_consumption=256 +opcache.interned_strings_buffer=16 +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,headers_sent,http_response_code,setcookie,session_create_id,session_id,session_name,session_save_path,session_status,session_start,session_write_close,set_time_limit \ No newline at end of file diff --git a/frameworks/PHP/php/deploy/workerman/composer.json b/frameworks/PHP/php/deploy/workerman/composer.json new file mode 100644 index 00000000000..263325313aa --- /dev/null +++ b/frameworks/PHP/php/deploy/workerman/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "joanhey/adapterman": "0.5" + } + } \ No newline at end of file diff --git a/frameworks/PHP/php/deploy/workerman/start.php b/frameworks/PHP/php/deploy/workerman/start.php new file mode 100644 index 00000000000..1bdc84945b9 --- /dev/null +++ b/frameworks/PHP/php/deploy/workerman/start.php @@ -0,0 +1,77 @@ +count = (int) shell_exec('nproc') * 4; +$web->name = 'workerman'; + +define('WEBROOT', '/php/'); + +$web->onWorkerStart = static function () { + Header::init(); +}; + +$web->onMessage = static function ($connection, $request) { + $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); + /* if ($path === '/') { + $connection->send(exec_php_file(WEBROOT.'/index.php', $request)); + return; + } */ + + $file = realpath(WEBROOT . $path); + if (false === $file || !str_ends_with($file, '.php')) { + http_response_code(404); + $connection->send('

404 Not Found

'); + return; + } + // Security check! + if (!str_starts_with($file, WEBROOT)) { + http_response_code(400); + $connection->send('

400 Bad Request

'); + return; + } + + header(Header::$date); // To pass the bench + $connection->send(exec_php_file($file)); +}; + +function exec_php_file($file) +{ + ob_start(); + // Try to include php file. + try { + include $file; + } catch (\Exception $e) { + echo $e; + } + return ob_get_clean(); +} + +class Header +{ + 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'; + }); + } +} + +Worker::runAll(); diff --git a/frameworks/PHP/php/php-workerman.dockerfile b/frameworks/PHP/php/php-workerman.dockerfile new file mode 100644 index 00000000000..2812878f999 --- /dev/null +++ b/frameworks/PHP/php/php-workerman.dockerfile @@ -0,0 +1,31 @@ +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 + +RUN apt-get install -yqq git unzip \ + php8.2 php8.2-common php8.2-cli php8.2-fpm php8.2-mysql > /dev/null + +RUN apt-get install -y php-pear php8.2-dev libevent-dev > /dev/null +RUN pecl install event-3.0.8 > /dev/null && echo "extension=event.so" > /etc/php/8.2/cli/conf.d/event.ini + +COPY deploy/workerman/cli-php.ini /etc/php/8.2/cli/php.ini + +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer + +ADD ./ /php +WORKDIR /php + +COPY deploy/workerman/composer.json ./ +RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet + +COPY deploy/workerman/start.php ./ + +RUN chmod -R 777 /php + +EXPOSE 8080 + +CMD php start.php start