Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nessor's avatar

[Docker & EC2] artisan extrem slow

Hey guys,

I'm playing around with Docker and Kubernetes on AWS at the moment and have a strange problem. My Laravel container, or framework, is extremely slow.

For example, here is an Artisan command executed directly in the running container:

root@laravel-deployment-645bfb8bb9-b9ljn:/var/www# time php artisan inspire     
An unexamined life is not worth living. - Socrates

real    2m3.451s
user    0m0.284s
sys     0m0.078s
root@laravel-deployment-645bfb8bb9-b9ljn:/var/www# 

The container is running on a t3.small instance with 20GB gp3 SSD.

To build the image I use this Dockerfile:

FROM php:8.0-fpm

# Set working directory
WORKDIR /var/www
COPY . .

# Set correct file access rights
RUN curl -fsSL https://deb.nodesource.com/setup_12.x | bash - \
    && apt-get update \
    && apt-get -y upgrade \
    && apt-get install -y --no-install-recommends \
        curl \
        libpng-dev \
        libonig-dev \
        libxml2-dev \
        libicu-dev \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
        zip \
        unzip \
        jpegoptim \
        optipng \
        pngquant \
        gifsicle \
        libzip-dev \
        nodejs \
    && npm install -g svgo \

    # Install PHP extensions
    && docker-php-ext-configure intl \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install \
        pdo \
        pdo_mysql \
        mbstring \
        intl\
        exif \
        gd \
        pcntl \
        bcmath \
        opcache \
        fileinfo \
        zip \
    && pecl install -o -f redis \
    && rm -rf /tmp/pear \
    && docker-php-ext-enable redis \

    #Clear caches
    && apt-get autoremove --yes \
    && apt-get clean autoclean \
    && rm -rf /var/lib/{apt,dpkg,cache,log}/

RUN find . -type d -exec chmod 0755 {} \; \
    && find . -type f -exec chmod 0644 {} \; \
    && chmod 774 artisan \
    && chown -R www-data:www-data . \
    && rm -R .deploy

If you need more information, please ask. I am not sure what information is useful here.

EDIT: Forgot to mention. I'm using Laravel v8.83.0 with PHP v8.0.15

EDIT2: I also found out that the artisan command uses >100MB of RAM after 1:30min.

0 likes
1 reply
nessor's avatar
nessor
OP
Best Answer
Level 1

I have found the problem. Apparently, Artisan also requires an active database connection. The security group in RDS was set so that Kubernetes did not have access to this yet. I suspect that artisan then ran into a timeout.

Please or to participate in this conversation.