Skip to content

Commit 3660a71

Browse files
authored
[php] Add Symfony Swoole using phpruntime (#7753)
* [php] Add Symfony with Swoole, using phpruntime * Enable display errors * Change environment Looks like Kaznova change it * Swoole delete broken tag * Update to php8.2 * php8.2-cli To use docker cache
1 parent dff47a1 commit 3660a71

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

frameworks/PHP/symfony/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
1515

1616
###> symfony/framework-bundle ###
17-
APP_ENV=dev
17+
APP_ENV=prod
1818
APP_SECRET=00708cd4c2a9090792f7bd68b094983d
1919
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
2020
#TRUSTED_HOSTS='^(localhost|example\.com)$'

frameworks/PHP/symfony/benchmark_config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
"database_os": "Linux",
6666
"display_name": "symfony-swoole",
6767
"notes": "",
68-
"versus": "swoole",
69-
"tags": ["broken"]
68+
"versus": "swoole"
7069
},
7170
"workerman": {
7271
"plaintext_url": "/plaintext",

frameworks/PHP/symfony/deploy/swoole/php.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
display_errors=Off
2-
display_startup_errors=Off
1+
display_errors=On
2+
display_startup_errors=On
33
short_open_tag=Off
44

55
session.gc_probability=0
66
session.gc_divisor=1000
77

8-
swoole.display_errors=Off
8+
swoole.display_errors=On
99

1010
memory_limit=512M
1111

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use App\Kernel;
4+
5+
$_SERVER['APP_RUNTIME_OPTIONS'] = [
6+
'host' => '0.0.0.0',
7+
'port' => 8080,
8+
'mode' => SWOOLE_BASE,
9+
'settings' => [
10+
\Swoole\Constant::OPTION_WORKER_NUM => swoole_cpu_num() * 2,
11+
\Swoole\Constant::OPTION_ENABLE_STATIC_HANDLER => true,
12+
\Swoole\Constant::OPTION_DOCUMENT_ROOT => dirname(__DIR__).'/public'
13+
],
14+
];
15+
16+
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
17+
18+
return function (array $context) {
19+
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
20+
};

frameworks/PHP/symfony/symfony-swoole.dockerfile

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,24 @@ RUN apt-get update -yqq && \
1010
apt-get install -yqq libicu-dev git unzip > /dev/null && \
1111
docker-php-ext-install pdo_mysql opcache intl > /dev/null
1212

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

1515
COPY deploy/swoole/php.ini /usr/local/etc/php/
16-
WORKDIR /symfony
17-
ADD ./composer.json /symfony/
18-
RUN mkdir -m 777 -p /symfony/var/cache/swoole /symfony/var/log
19-
RUN COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --no-scripts
20-
21-
# downgrade to doctrine-dbal 2.12 => due to a bug in version 2.13
22-
# see https://github.com/doctrine/dbal/issues/4603
23-
#RUN composer require doctrine/orm:2.8.5 -W
24-
#RUN composer require doctrine/dbal:2.12.x -W
2516

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

31-
# removes hardcoded option `ATTR_STATEMENT_CLASS` conflicting with `ATTR_PERSISTENT`. Hack not needed when upgrading to Doctrine 3
32-
# see https://github.com/doctrine/dbal/issues/2315
33-
#RUN sed -i '/PDO::ATTR_STATEMENT_CLASS/d' ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php
23+
ENV APP_RUNTIME=Runtime\\Swoole\\Runtime
24+
RUN composer require runtime/swoole
3425

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

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

4131
EXPOSE 8080
4232

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

0 commit comments

Comments
 (0)