Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[php] Symfony with Workerman #7627

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions frameworks/PHP/symfony/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"database": "MySQL",
"framework": "symfony",
"language": "PHP",
"flavor": "PHP7",
"flavor": "PHP8",
"orm": "Full",
"platform": "FPM/FastCGI",
"webserver": "nginx",
Expand All @@ -34,7 +34,7 @@
"database": "MySQL",
"framework": "symfony",
"language": "PHP",
"flavor": "PHP7",
"flavor": "PHP8",
"orm": "Raw",
"platform": "FPM/FastCGI",
"webserver": "nginx",
Expand Down Expand Up @@ -67,6 +67,29 @@
"notes": "",
"versus": "swoole",
"tags": ["broken"]
},
"workerman": {
"plaintext_url": "/plaintext",
"json_url": "/json",
"db_url": "/db",
"update_url": "/updates?queries=",
"query_url": "/queries?queries=",
"fortune_url": "/fortunes",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "MySQL",
"framework": "symfony",
"language": "PHP",
"flavor": "PHP8",
"orm": "Full",
"platform": "workerman",
"webserver": "None",
"os": "Linux",
"database_os": "Linux",
"display_name": "symfony-workerman",
"notes": "",
"versus": "php"
}
}]
}
3 changes: 2 additions & 1 deletion frameworks/PHP/symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"symfony/framework-bundle": "^6.0",
"symfony/orm-pack": "^2.1",
"symfony/twig-bundle": "^6.0",
"symfony/yaml": "^6.0"
"symfony/yaml": "^6.0",
"joanhey/adapterman": "0.4"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
16 changes: 16 additions & 0 deletions frameworks/PHP/symfony/deploy/conf/cli-php.ini
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions frameworks/PHP/symfony/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
require_once __DIR__ . '/vendor/autoload.php';


use Adapterman\Adapterman;
use Workerman\Worker;
use Workerman\Lib\Timer;

Adapterman::init();

$http_worker = new Worker('http://0.0.0.0:8080');
$http_worker->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;
}
48 changes: 48 additions & 0 deletions frameworks/PHP/symfony/start.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/vendor/autoload.php';

(new Dotenv())->bootEnv(__DIR__.'/.env');

if ($_SERVER['APP_DEBUG']) {
umask(0000);

Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}

global $kernel;

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);

function run()
{
global $kernel;

ob_start();
try {
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$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();
}
40 changes: 40 additions & 0 deletions frameworks/PHP/symfony/symfony-workerman.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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

EXPOSE 8080

WORKDIR /symfony
ADD ./composer.json /symfony/
RUN mkdir -m 777 -p /symfony/var/cache/{dev,prod} /symfony/var/log
RUN composer install --no-dev --no-scripts

# downgrade to doctrine-dbal 2.12 => due to a bug in version 2.13
# see https://github.com/doctrine/dbal/issues/4603
#RUN composer require doctrine/orm:2.10.2 -W
#RUN composer require doctrine/dbal:2.12.x -W

ADD . /symfony
RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-autoload --no-dev --classmap-authoritative
RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-env prod

# removes hardcoded option `ATTR_STATEMENT_CLASS` conflicting with `ATTR_PERSISTENT`. Hack not needed when upgrading to Doctrine 3
# see https://github.com/doctrine/dbal/issues/2315
#RUN sed -i '/PDO::ATTR_STATEMENT_CLASS/d' ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php

RUN php bin/console cache:clear

COPY deploy/conf/cli-php.ini /etc/php/8.1/cli/php.ini

CMD php server.php start