View Issue Details

IDProjectCategoryView StatusLast Update
0002106XdebugCode Coveragepublic2022-08-09 17:35
Reporternetdjw Assigned To 
PrioritynormalSeveritycrashReproducibilityalways
Status newResolutionopen 
OSAlpine Linux in Docker 
Product Version3.1.5 
Summary0002106: phpunit runs out of memory & runs much more slower than without xdebug
Description

In my Laravel project I have 1349 tests. I try to run phpunit in a Docker container. Some test are failing, but it's not a problem.

When I start phpunit with this command:

docker-compose run --rm phpunit --coverage-html

Then I get this output:

E.I.F....FFFF............FF.FF...............................   61 / 1349 (  4%)
.............................................................  122 / 1349 (  9%)
.............................................................  183 / 1349 ( 13%)
...........................djw@DESKTOP $

The djw@DESKTOP $ part is my console promt string. It means phpunit died without any error message.

I tried to run phpunit without xdebug. In this case it can run all tests and create an error & fail reports as it should be.

I tried to run phpunit pcov instead of xdebug, it can run also without die.

When I run phpunit without --coverage-html option, it't runs smoothly. But with this option it start tests and new dots showing slowly and slowly and then stops showing new dots. But the processor usage grow up to 100%, memory usage also growing up to 100%, then swap is runs out, and then the container dies.

Based on this test cases I think the problem is with xdebug.

Here is my phpunit.dockerfile:

FROM php:8.1-fpm-alpine

WORKDIR /var/www/html

RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

ENV PHP_MEMORY_LIMIT=1G
ENV PHP_UPLOAD_MAX_FILESIZE: 512M
ENV PHP_POST_MAX_SIZE: 512M

RUN docker-php-ext-install pdo

RUN apk add --no-cache libpng libpng-dev && docker-php-ext-install gd && apk del libpng-dev

RUN apk update \
    && apk upgrade \
    && apk add --no-cache \
        freetype \
        libpng \
        libjpeg-turbo \
        freetype-dev \
        libpng-dev \
        jpeg-dev \
        libwebp-dev \
        libjpeg \
        libjpeg-turbo-dev

RUN docker-php-ext-configure gd \
        --with-freetype=/usr/lib/ \
        --with-jpeg=/usr/lib/ \
        --with-webp=/usr

RUN NUMPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
    && docker-php-ext-install -j${NUMPROC} gd

RUN apk add --no-cache sqlite-libs
RUN apk add --no-cache icu sqlite git openssh zip
RUN apk add --no-cache --virtual .build-deps icu-dev libxml2-dev sqlite-dev curl-dev
RUN docker-php-ext-install \
        bcmath \
        curl \
        ctype \
        intl \
        pdo \
        pdo_sqlite \
        xml
RUN apk del .build-deps

RUN docker-php-ext-enable pdo_sqlite

# Add xdebug
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS
RUN apk add --update linux-headers
RUN pecl install xdebug-3.1.5
RUN docker-php-ext-enable xdebug
RUN apk del -f .build-deps

# Configure Xdebug
RUN echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.log=/var/www/html/xdebug/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.discover_client_host=1" >> /usr/local/etc/php/conf.d/xdebug.ini

RUN echo memory_limit = -1 >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;

Is there any option to tell phpunit the maximum usable memory size or something other trick to avoid this issue?

Additional Information

PHP version 8.1.6

Tagsalpine, coverage, crash, Docker, fpm, php8.1
Operating System
PHP Version8.1.0-8.1.4

Activities

derick

2022-08-09 09:58

administrator   ~0006352

Is there any option to tell phpunit the maximum usable memory size or something other trick to avoid this issue?

Yes, that is easy. Dont set the memory limit to -1 as you've done with this docker config line:

RUN echo memory_limit = -1 >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;

But in general, I expect the code to run about 10-20 times as slow, and using a lot more memory. Are you should have you have enough and your machine didn't start swapping?

derick

2022-08-09 09:59

administrator   ~0006353

@j-hotlink I think your issue is unrelated, can you create a new one — and include a way for me to reproduce this fully. I'll mark your comment as private in here.

netdjw

2022-08-09 13:57

reporter   ~0006356

But in general, I expect the code to run about 10-20 times as slow, and using a lot more memory. Are you should have you have enough and your machine didn't start swapping?

I tried to remove that line, but then docker died after filled every available memory space. RAM and swap too. So noting difference.

Issue History

Date Modified Username Field Change
2022-07-27 08:23 netdjw New Issue
2022-07-27 08:23 netdjw Tag Attached: alpine
2022-07-27 08:23 netdjw Tag Attached: coverage
2022-07-27 08:23 netdjw Tag Attached: crash
2022-07-27 08:23 netdjw Tag Attached: Docker
2022-07-27 08:23 netdjw Tag Attached: fpm
2022-07-27 08:23 netdjw Tag Attached: php8.1
2022-08-09 09:58 derick Note Added: 0006352
2022-08-09 09:59 derick Note Added: 0006353
2022-08-09 13:57 netdjw Note Added: 0006356