skip to Main Content

In my Laravel project I upgraded to currently latest Laravel 9.3.0 and PHP 8.0.16.

The original version was Laravel 8.64 with PHP 7.4.

I run the project in Docker containers with php:8.0.16-fpm-alpine image. Previous was php:7.4-fpm-alpine.

This is my Docker container config in docker-compose.yml file:

version: "3"
services:
  php:
    build:
      context: ./.docker-config/dockerfiles
      dockerfile: php.dockerfile
    volumes:
      - ./laravel:/var/www/html:delegated
    networks:
      - mynetwork

And here is the php.dockerfile:

FROM php:8.0.16-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=2G
ENV PHP_UPLOAD_MAX_FILESIZE: 512M
ENV PHP_POST_MAX_SIZE: 512M

RUN docker-php-ext-install pdo pdo_mysql
# ...

As you see I set 2 GB for PHP memory limit.

When I run docker-compose run --rm phpunit I get this error:

PHPUnit 9.5.16 by Sebastian Bergmann and contributors.

...............................................................  63 / 281 ( 22%)
......................
   SymfonyComponentErrorHandlerErrorFatalError

  Allowed memory size of 134217728 bytes exhausted (tried to allocate 5242880 bytes)

  at database/migrations/2022_01_21_120600_create_tags_table.php:16
     12▕      * @return void
     13▕      */
     14▕     public function up()
     15▕     {
  ➜  16▕         Schema::create('tags', function (Blueprint $table) {
     17▕             $table->id();
     18▕             $table->string('name')->default('');
     19▕             $table->string('type')->default('');
     20▕             $table->string('color', 7)->default('');

Here is the referred migration file. I think, nothing special:

<?php

use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tags', function (Blueprint $table) {
            $table->id();
            $table->string('name')->default('');
            $table->string('type')->default('');
            $table->string('color', 7)->default('');
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('tags');
    }
};

Earlier same error happend on different migration file.

Any idea what’s going on and how can I solve this issue?

Thanks!

2

Answers


  1. You can use in Dockerfile for solving memory limitation

    RUN echo memory_limit = -1 >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;
    
    Login or Signup to reply.
  2. For the record, I’m running into the same issue. Also after a Laravel 8->9 upgrade. And also specifically at various migrations.

    I’ll keep on searching for a solution, but since we both suffer the same issue in the same situation, it might be related to the Laravel 9 upgrade.

    EDIT: It turns out php8 and/or php unit has a memory leak. The reason why this gave me real issues is that it turned out I had a manual memory override in my code somewhere:

    ini_set('memory_limit', '256M');
    

    After removing this, my tests run without issues. Of course this isn’t a solution for the memory leaks, but at least my tests are able to run.

    If you have the same issues, check your code for similar mistakes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search