From 06faf285c3ba6ef3518eb38b3e97cb3298dfdc29 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Mon, 17 Oct 2022 17:00:32 +0200 Subject: [PATCH 1/5] Laravel Workerman --- frameworks/PHP/laravel/benchmark_config.json | 23 ++++++ .../PHP/laravel/deploy/conf/cli-php.ini | 16 ++++ .../laravel/deploy/workerman/composer.json | 58 ++++++++++++++ frameworks/PHP/laravel/index-man.php | 75 +++++++++++++++++++ .../PHP/laravel/laravel-workerman.dockerfile | 33 ++++++++ frameworks/PHP/laravel/server-man.php | 32 ++++++++ 6 files changed, 237 insertions(+) create mode 100644 frameworks/PHP/laravel/deploy/conf/cli-php.ini create mode 100644 frameworks/PHP/laravel/deploy/workerman/composer.json create mode 100644 frameworks/PHP/laravel/index-man.php create mode 100644 frameworks/PHP/laravel/laravel-workerman.dockerfile create mode 100644 frameworks/PHP/laravel/server-man.php diff --git a/frameworks/PHP/laravel/benchmark_config.json b/frameworks/PHP/laravel/benchmark_config.json index 014deb03196..34f9383d357 100644 --- a/frameworks/PHP/laravel/benchmark_config.json +++ b/frameworks/PHP/laravel/benchmark_config.json @@ -92,6 +92,29 @@ "display_name": "laravel-roadrunner", "notes": "", "versus": "swoole" + }, + "workerman": { + "json_url": "/json", + "db_url": "/db", + "query_url": "/queries/", + "fortune_url": "/fortunes", + "update_url": "/updates/", + "plaintext_url": "/plaintext", + "port": 8080, + "approach": "Realistic", + "classification": "Fullstack", + "database": "MySQL", + "framework": "laravel", + "language": "PHP", + "flavor": "PHP8.1", + "orm": "Full", + "platform": "workerman", + "webserver": "None", + "os": "Linux", + "database_os": "Linux", + "display_name": "laravel", + "notes": "", + "versus": "php" } }] } \ No newline at end of file diff --git a/frameworks/PHP/laravel/deploy/conf/cli-php.ini b/frameworks/PHP/laravel/deploy/conf/cli-php.ini new file mode 100644 index 00000000000..f4ad7564e46 --- /dev/null +++ b/frameworks/PHP/laravel/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,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/laravel/deploy/workerman/composer.json b/frameworks/PHP/laravel/deploy/workerman/composer.json new file mode 100644 index 00000000000..3e8ca3dd912 --- /dev/null +++ b/frameworks/PHP/laravel/deploy/workerman/composer.json @@ -0,0 +1,58 @@ +{ + "name": "laravel/laravel", + "type": "project", + "description": "The Laravel Framework.", + "keywords": [ + "framework", + "laravel" + ], + "license": "MIT", + "require": { + "php": "^8.0", + "laravel/framework": "^8.0", + "joanhey/adapterman": "0.4" + }, + "require-dev": { + "facade/ignition": "^2.3.6", + "fzaninotto/faker": "^1.9.1", + "mockery/mockery": "^1.3.1", + "nunomaduro/collision": "^5.0", + "phpunit/phpunit": "^9.3" + }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + }, + "extra": { + "laravel": { + "dont-discover": [] + } + }, + "autoload": { + "psr-4": { + "App\\": "app/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "post-autoload-dump": [ + "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", + "@php artisan package:discover --ansi" + ], + "post-root-package-install": [ + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + ], + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ] + } +} + + diff --git a/frameworks/PHP/laravel/index-man.php b/frameworks/PHP/laravel/index-man.php new file mode 100644 index 00000000000..877b5848e38 --- /dev/null +++ b/frameworks/PHP/laravel/index-man.php @@ -0,0 +1,75 @@ + + */ + +define('LARAVEL_START', microtime(true)); + +/* +|-------------------------------------------------------------------------- +| Register The Auto Loader +|-------------------------------------------------------------------------- +| +| Composer provides a convenient, automatically generated class loader for +| our application. We just need to utilize it! We'll simply require it +| into the script here so that we don't have to worry about manual +| loading any of our classes later on. It feels great to relax. +| +*/ + +require __DIR__.'/vendor/autoload.php'; + +/* +|-------------------------------------------------------------------------- +| Turn On The Lights +|-------------------------------------------------------------------------- +| +| We need to illuminate PHP development, so let us turn on the lights. +| This bootstraps the framework and gets it ready for use, then it +| will load up this application so that we can run it and send +| the responses back to the browser and delight our users. +| +*/ + +$app = require_once __DIR__.'/bootstrap/app.php'; + +/* +|-------------------------------------------------------------------------- +| Run The Application +|-------------------------------------------------------------------------- +| +| Once we have the application, we can handle the incoming request +| through the kernel, and send the associated response back to +| the client's browser allowing them to enjoy the creative +| and wonderful application we have prepared for them. +| +*/ +global $kernel; + +$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); + + +function run() +{ + global $kernel; + + ob_start(); + try { + $response = $kernel->handle( + $request = Illuminate\Http\Request::capture() + ); + + $response->send(); + header('Date: ' . Header::$date); // To pass the bench, nginx auto add it + + $kernel->terminate($request, $response); + } catch (Throwable $e) { + echo $e->getMessage(); + } + + return ob_get_clean(); +} diff --git a/frameworks/PHP/laravel/laravel-workerman.dockerfile b/frameworks/PHP/laravel/laravel-workerman.dockerfile new file mode 100644 index 00000000000..42a04406f9d --- /dev/null +++ b/frameworks/PHP/laravel/laravel-workerman.dockerfile @@ -0,0 +1,33 @@ +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 git unzip \ + php8.1-cli php8.1-mysql php8.1-mbstring 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 + +ADD ./ /laravel +WORKDIR /laravel + +EXPOSE 8080 + +RUN mkdir -p /laravel/bootstrap/cache /laravel/storage/logs /laravel/storage/framework/sessions /laravel/storage/framework/views /laravel/storage/framework/cache +RUN chmod -R 777 /laravel + +COPY deploy/workerman/composer.json ./ +RUN composer install --optimize-autoloader --classmap-authoritative --no-dev +RUN php artisan optimize + +COPY deploy/conf/cli-php.ini /etc/php/8.1/cli/php.ini + +#RUN sed -i 's|$app->run();|//$app->run();|g' index.php +#RUN sed -i 's|//PDO::ATTR_EMULATE_PREPARES|PDO::ATTR_EMULATE_PREPARES|g' index.php + +CMD php server-man.php start diff --git a/frameworks/PHP/laravel/server-man.php b/frameworks/PHP/laravel/server-man.php new file mode 100644 index 00000000000..05ec74af0d5 --- /dev/null +++ b/frameworks/PHP/laravel/server-man.php @@ -0,0 +1,32 @@ +count = (int) shell_exec('nproc') * 4; +$http_worker->name = 'AdapterMan-Laravel'; +$http_worker->onWorkerStart = function () { + Header::$date = gmdate('D, d M Y H:i:s').' GMT'; + Timer::add(1, function() { + Header::$date = gmdate('D, d M Y H:i:s').' GMT'; + }); + //init(); + require __DIR__.'/index-man.php'; +}; + +$http_worker->onMessage = static function ($connection, $request) { + + $connection->send(run()); +}; + +Worker::runAll(); + +class Header { + public static $date; +} \ No newline at end of file From 0d18bda00d5042fdaf96248705ceb87ad8410a25 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Mon, 17 Oct 2022 17:05:10 +0200 Subject: [PATCH 2/5] Small change to run CI --- frameworks/PHP/laravel/index-man.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/PHP/laravel/index-man.php b/frameworks/PHP/laravel/index-man.php index 877b5848e38..6f711e6cc22 100644 --- a/frameworks/PHP/laravel/index-man.php +++ b/frameworks/PHP/laravel/index-man.php @@ -48,7 +48,7 @@ | and wonderful application we have prepared for them. | */ -global $kernel; +global $kernel; $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); From 4f2bacd800b4731b6af27c9ee7ce92f318a36265 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Mon, 17 Oct 2022 18:59:18 +0200 Subject: [PATCH 3/5] [ci skip] Add display_name --- frameworks/PHP/laravel/benchmark_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/PHP/laravel/benchmark_config.json b/frameworks/PHP/laravel/benchmark_config.json index 34f9383d357..63c99532f2a 100644 --- a/frameworks/PHP/laravel/benchmark_config.json +++ b/frameworks/PHP/laravel/benchmark_config.json @@ -112,7 +112,7 @@ "webserver": "None", "os": "Linux", "database_os": "Linux", - "display_name": "laravel", + "display_name": "laravel-workerman", "notes": "", "versus": "php" } From 3aca51d2629571aba09a9d7bda6288b0685e4db6 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Mon, 17 Oct 2022 19:12:09 +0200 Subject: [PATCH 4/5] Change name index-man.php to start.php --- frameworks/PHP/laravel/server-man.php | 2 +- frameworks/PHP/laravel/{index-man.php => start.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename frameworks/PHP/laravel/{index-man.php => start.php} (100%) diff --git a/frameworks/PHP/laravel/server-man.php b/frameworks/PHP/laravel/server-man.php index 05ec74af0d5..fcee2ad4bed 100644 --- a/frameworks/PHP/laravel/server-man.php +++ b/frameworks/PHP/laravel/server-man.php @@ -17,7 +17,7 @@ Header::$date = gmdate('D, d M Y H:i:s').' GMT'; }); //init(); - require __DIR__.'/index-man.php'; + require __DIR__.'/start.php'; }; $http_worker->onMessage = static function ($connection, $request) { diff --git a/frameworks/PHP/laravel/index-man.php b/frameworks/PHP/laravel/start.php similarity index 100% rename from frameworks/PHP/laravel/index-man.php rename to frameworks/PHP/laravel/start.php From dd20c805bccec95db26f311be4113a49419e5820 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Mon, 17 Oct 2022 19:36:58 +0200 Subject: [PATCH 5/5] Small change to rerun CI --- frameworks/PHP/laravel/start.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/PHP/laravel/start.php b/frameworks/PHP/laravel/start.php index 6f711e6cc22..b5b34b0ed4b 100644 --- a/frameworks/PHP/laravel/start.php +++ b/frameworks/PHP/laravel/start.php @@ -48,7 +48,8 @@ | and wonderful application we have prepared for them. | */ -global $kernel; + +global $kernel; $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);