Reputation: 19695
I have dockerized my laravel app, here is the docker-compose:
version: '3'
services:
app:
image: xoco/kendozone:local-1.0.0
ports:
- "80:80"
And Dockerfile:
FROM php:7.1.14-fpm
LABEL maintainer="[email protected]"
LABEL version="1.0.0"
LABEL description="Kendozone is a online tournament webapp coded with PHP / Laravel"
ENV node_version 8.4.0
ENV npm_version 5.7.1
ENV NVM_DIR /.nvm
ENV APP_DIR="/var/www"
ENV APP_PORT="80"
RUN echo "deb http://ftp.de.debian.org/debian stretch main " >> /etc/apt/sources.list \
&& apt-get update -y && apt-get install -y openssl zip unzip git automake \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
libmagickwand-dev vim --no-install-recommends \
&& apt-get remove -y libgnutls-deb0-28 \
&& apt-get purge --auto-remove -y g++ \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install pdo pdo_mysql mbstring zip -j$(nproc) iconv mcrypt -j$(nproc) gd
WORKDIR $APP_DIR
COPY . $APP_DIR
RUN mkdir -p $APP_DIR/resources/assets/less/_main_full \
&& touch $APP_DIR/resources/assets/less/_main_full/main.less \
&& touch $APP_DIR/sqlite.db \
&& mv .env.local .env \
&& chown -R www-data:www-data $APP_DIR
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --no-interaction
RUN mkdir -p $NVM_DIR && chown -R www-data:www-data $NVM_DIR
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" \
&& nvm install ${node_version}
ENV NODE_PATH $NVM_DIR/v$node_version/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$node_version/bin:$PATH
RUN npm install
RUN npm run production
RUN php artisan key:generate
RUN php artisan migrate --seed
CMD php artisan serve --host=0.0.0.0 --port=$APP_PORT
THing is app is reponding when hitting:
http://127.0.0.1 but it takes more than 2 minutes to load login screen, and css is not well displayed.
But when I use chrome debugger to check requests, all the requests give a 200 response which is great, I can click on all links, which means css and js are resolved without any problems.
Why is it happening ?
EDIT: On my mac, the page load is quite normal, but in CentOs, it is quite long.
Upvotes: 1
Views: 1569
Reputation: 7793
Inspecting the request with Chrome Debugger, I noticed that the TTFB
is unbelievably long. It is 17.14s on my computer. The subsequent requests are relatively faster.
TTFB
stands for Time To First Byte. A high TTFB
indicates an error or a mis-behavior on the server side.
After the first request, I executed a docker diff
command, and found out the following changes in the container:
$ docker diff xxx
C /root
C /var/www/database
C /var/www/database/sqlite.db
C /var/www/storage/framework/views
A /var/www/storage/framework/views/3d3947126b3224667121e9703252617b7f23f88b.php
A /var/www/storage/framework/views/62a19b65f14428bd14bd13be0dce90ea16887a78.php
A /var/www/storage/framework/views/7a212b1361bf8a55442817d40915d62cab0878dd.php
A /var/www/storage/framework/views/beafc1ea6ba3b1c45604098b20ce357eac86e9d6.php
A /var/www/storage/framework/views/d58ea65ce5486bc3c5f9d4623e2e3952bb1efc51.php
A /var/www/storage/framework/views/e1754d32beb46c021e4c4c924ed9b0d38d671fb4.php
A /var/www/storage/framework/views/f0565996f52733a0597399e7a8c558ebf88e6a9e.php
This means that the first request causes the server side to process some hard work (a change to the sqlite.db and creation of some PHP files). These changes are cached so the subsequent requests are relatively faster.
My guess is that this problem is caused by the view function that handles the login page. But I'm not 100% sure as I haven't traced app's CPU usage during the request.
Hope that could help.
Upvotes: 2