I am running mezzio swoole application in production in aws. Recently my local installation of the production version which was served on localhost:9501 started not to respond (no change made to the code, except composer update). It is running in a docker container with php8.0. With infininte loading of the url localhost:9501, I noticed that the cpu usage of the container is above 200%. Now I have pinned down the area of cpu usage as the moment when mezzio:swoole:start is called. Is there any possibility for this unexpected behavior.
The docker file that creates the container is as follows:
FROM ubuntu:latest
#the following ARG turns off the questions normally asked for location and timezone for Apache
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
RUN apt update
RUN apt install -y nano
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:ondrej/php
# Install PHP-fpm &onfigure Apache to use our PHP-FPM socket for all PHP files
RUN apt install -y php8.0-fpm
#RUN a2enconf php8.0-fpm
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
EXPOSE 80
RUN apt-get update \
&& apt-get install -y \
libxml2-dev \
git \
libzip-dev
RUN apt-get update \
&& apt-get install -y \
php8.0-mysqli \
php8.0-common \
php8.0-mysql \
php8.0-intl
RUN apt-get update \
&& apt-get install -y \
php8.0-gd \
php8.0-opcache \
php8.0-xml \
php8.0-bcmath \
php8.0-curl
COPY ./docker/web/docker-php-ext-enable /usr/local/bin
COPY ./docker/web/docker-php-ext-install /usr/local/bin
COPY ./docker/web/docker-php-source /usr/local/bin
COPY ./docker/web/docker-php-ext-configure /usr/local/bin
COPY ./docker/web/docker-php-entrypoint /usr/local/bin
RUN chmod +x /usr/local/bin/docker-php-ext-enable && \
chmod +x /usr/local/bin/docker-php-ext-install && \
chmod +x /usr/local/bin/docker-php-source && \
chmod +x /usr/local/bin/docker-php-ext-configure && \
chmod +x /usr/local/bin/docker-php-entrypoint
RUN apt-get update && apt-get install -y \
php8.0-xml \
apt-utils \
php-pear \
php-dev
#&& pecl install inotify
RUN apt-get update && apt-get install -y \
php-xml php8.0-zip php8.0-mbstring \
&& pecl install inotify openswoole
RUN apt-get update && apt-get install -y vim
RUN add-apt-repository ppa:openswoole/ppa -y \
&& apt-get install -y php8.0-openswoole php8.0-inotify \
php8.0-redis \
php8.0-memcached
CMD service php8.0-fpm start -D FOREGROUND
COPY ./docker/web/start_mezzio.sh /tmp
RUN chmod +x /tmp/start_mezzio.sh
COPY ./ /var/www/app-name
COPY ./docker/web/reload.sh /var/www
EXPOSE 80 9501
ENTRYPOINT ["/tmp/start_mezzio.sh"]
type or paste code here
Here start_mezzio shell script is used to start the mezzio swoole server and reload.sh just reloads the container with mezzio:swoole:reload. And this container is now in production without any issues. On my system, localhost:9501 keeps on loading without any response and cpu usage is above 200%. Requesting your kind support. Adding my swoole.local.php file contents
<?php
declare(strict_types=1);
use App\LoggingListener;
use Mezzio\Swoole\Event\HotCodeReloaderWorkerStartListener;
use Mezzio\Swoole\Event\TaskEvent;
use Mezzio\Swoole\Event\WorkerStartEvent;
use Mezzio\Swoole\Task\TaskEventDispatchListener;
return [
'mezzio-swoole' => [
'swoole-http-server' => [
'host' => '0.0.0.0',
'port' => 9501,
'mode' => SWOOLE_PROCESS,
'options' => [
'open_tcp_keepalive'=>true,
'heartbeat_idle_time'=>28800,
'heartbeat_check_interval'=>false,
'enable_delay_receive'=>false,
'reload_async'=>false,
'worker_num' => 2, // The number of HTTP Server Workers
'task_worker_num' => 2, // The number of Task Workers
'task_enable_coroutine' => true, // optional to turn on task coroutine support
],
// Here - enabling monolog logger
'logger' => [
'logger-name' => 'logger-sys',
],
],
'process-name' => 'app-name',
'listeners'=>[
// TaskEvent::class => [
// TaskEventDispatchListener::class,
// ],
WorkerStartEvent::class => [
HotCodeReloaderWorkerStartListener::class,
],
],
'hot-code-reload' => [
// Set to true to enable hot code reload; the default is false.
'enable' => false,
// Time in milliseconds between checks to changes in files.
'interval' => 500,
'paths' => [
// List of paths, either files or directories, to scan for changes.
// By default this is empty; you will need to configure it.
// A common value:
getcwd(),
'/',
'/var/www/app-name',
],
],
],
];