diff --git a/frameworks/PHP/laravel/benchmark_config.json b/frameworks/PHP/laravel/benchmark_config.json index 014deb03196..63c99532f2a 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-workerman", + "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/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..fcee2ad4bed --- /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__.'/start.php'; +}; + +$http_worker->onMessage = static function ($connection, $request) { + + $connection->send(run()); +}; + +Worker::runAll(); + +class Header { + public static $date; +} \ No newline at end of file diff --git a/frameworks/PHP/laravel/start.php b/frameworks/PHP/laravel/start.php new file mode 100644 index 00000000000..b5b34b0ed4b --- /dev/null +++ b/frameworks/PHP/laravel/start.php @@ -0,0 +1,76 @@ + + */ + +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(); +}