Skip to content

[php] Add Symfony Swoole using phpruntime #7753

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

Merged
merged 6 commits into from
Nov 29, 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
2 changes: 1 addition & 1 deletion frameworks/PHP/symfony/.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_ENV=prod
APP_SECRET=00708cd4c2a9090792f7bd68b094983d
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
#TRUSTED_HOSTS='^(localhost|example\.com)$'
Expand Down
3 changes: 1 addition & 2 deletions frameworks/PHP/symfony/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
"database_os": "Linux",
"display_name": "symfony-swoole",
"notes": "",
"versus": "swoole",
"tags": ["broken"]
"versus": "swoole"
},
"workerman": {
"plaintext_url": "/plaintext",
Expand Down
6 changes: 3 additions & 3 deletions frameworks/PHP/symfony/deploy/swoole/php.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
display_errors=Off
display_startup_errors=Off
display_errors=On
display_startup_errors=On
short_open_tag=Off

session.gc_probability=0
session.gc_divisor=1000

swoole.display_errors=Off
swoole.display_errors=On

memory_limit=512M

Expand Down
20 changes: 20 additions & 0 deletions frameworks/PHP/symfony/public/swoole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use App\Kernel;

$_SERVER['APP_RUNTIME_OPTIONS'] = [
'host' => '0.0.0.0',
'port' => 8080,
'mode' => SWOOLE_BASE,
'settings' => [
\Swoole\Constant::OPTION_WORKER_NUM => swoole_cpu_num() * 2,
\Swoole\Constant::OPTION_ENABLE_STATIC_HANDLER => true,
\Swoole\Constant::OPTION_DOCUMENT_ROOT => dirname(__DIR__).'/public'
],
];

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
33 changes: 11 additions & 22 deletions frameworks/PHP/symfony/symfony-swoole.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,24 @@ RUN apt-get update -yqq && \
apt-get install -yqq libicu-dev git unzip > /dev/null && \
docker-php-ext-install pdo_mysql opcache intl > /dev/null

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

COPY deploy/swoole/php.ini /usr/local/etc/php/
WORKDIR /symfony
ADD ./composer.json /symfony/
RUN mkdir -m 777 -p /symfony/var/cache/swoole /symfony/var/log
RUN COMPOSER_ALLOW_SUPERUSER=1 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.8.5 -W
#RUN composer require doctrine/dbal:2.12.x -W

ADD . /symfony
RUN COMPOSER_ALLOW_SUPERUSER=1 composer require "k911/swoole-bundle:^0.10" --no-scripts --with-all-dependencies
RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-autoload --no-dev --classmap-authoritative
RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-env swoole
WORKDIR /symfony
RUN mkdir -m 777 -p /symfony/var/cache/{dev,prod} /symfony/var/log
#RUN mkdir -m 777 -p /symfony/var/cache/swoole /symfony/var/log
RUN COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --no-scripts --quiet

# 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
ENV APP_RUNTIME=Runtime\\Swoole\\Runtime
RUN composer require runtime/swoole

# Force debug=0 because env is not "prod"
ENV APP_DEBUG=0
RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-autoload --no-dev --classmap-authoritative
RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-env prod

RUN php bin/console cache:clear
RUN echo "opcache.preload=/symfony/var/cache/swoole/App_KernelSwooleContainer.preload.php" >> /usr/local/etc/php/php.ini
#ENV APP_DEBUG=1

EXPOSE 8080

USER www-data
CMD php bin/console swoole:server:run
CMD php /symfony/public/swoole.php