Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal error: Allowed memory size of x bytes exhausted #224

Closed
Elmardus opened this issue Jan 18, 2018 · 9 comments
Closed

PHP Fatal error: Allowed memory size of x bytes exhausted #224

Elmardus opened this issue Jan 18, 2018 · 9 comments

Comments

@Elmardus
Copy link

When trying to generate image previews using the occ preview:generate-all command, The following error is thrown:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 12288 bytes) in /var/www/html/lib/private/legacy/image.php on line 477

According to phpinfo() the memory_limit is set to 128M. Can this be increased? I could not find a php.ini file to change this variable. Changing it to 2048M in .htacces and .user.ini did not resolve the issue.

I am running the standard docker image (not using docker-compose).

@Elmardus
Copy link
Author

I've checked all config files for a reference to the 128M memory, but I cannot locate it.
These are the config files according to php -i

Configuration File (php.ini) Path => /usr/local/etc/php
Loaded Configuration File => (none)
Scan this dir for additional .ini files => /usr/local/etc/php/conf.d
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini,
/usr/local/etc/php/conf.d/docker-php-ext-exif.ini,
/usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
/usr/local/etc/php/conf.d/docker-php-ext-intl.ini,
/usr/local/etc/php/conf.d/docker-php-ext-ldap.ini,
/usr/local/etc/php/conf.d/docker-php-ext-mcrypt.ini,
/usr/local/etc/php/conf.d/docker-php-ext-memcached.ini,
/usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini,
/usr/local/etc/php/conf.d/docker-php-ext-opcache.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_pgsql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pgsql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-redis.ini,
/usr/local/etc/php/conf.d/docker-php-ext-zip.ini,
/usr/local/etc/php/conf.d/opcache-recommended.ini

However the only references to 'memory' are set in opcache-recommended and .user.ini, and I've set them both to 512M without avail.
/usr/local/etc/php/php.ini does not exist, is that a problem?

@Elmardus
Copy link
Author

Elmardus commented Jan 19, 2018

I managed to fix the memory limit by manually creating /usr/local/etc/php/php.ini in the docker container, changing it to the correct user/group, and adding this single line:
memory_limit=512M
I was then able to pre-generate my gallery previews, which was running out of memory with 128M limit.

It seems that the memory directives in opcache-recommended.ini and .user.ini have an effect on the local value according to phpinfo, but does not edit the master value. Is this a bug?

@SnowMB
Copy link
Contributor

SnowMB commented Jan 28, 2018

Duplicate of #182

@SnowMB SnowMB marked this as a duplicate of #182 Jan 28, 2018
@SnowMB SnowMB closed this as completed Jan 28, 2018
@sitetester
Copy link

sitetester commented Apr 6, 2019

I fixed this problem by

  • creating custom /usr/local/etc/php/php.ini file inside container
  • putting ONLY memory_limit=1024M in new file ;)
  • checking new memory using php -r "echo ini_get('memory_limit').PHP_EOL;"
  • & that's all 😆

@Namone
Copy link

Namone commented Oct 1, 2019

Another method, that I found a bit more reliable (because it takes precedent over other php.ini settings,) is to create a custom config file.

  1. Create a file on your host machine. In my case, I was updating the max upload size: /Users/[username]/docker/php/uploads.ini

  2. Add custom settings to your new file:

max_execution_time=600
memory_limit=-1
upload_max_filesize = 64M

... any other settings
  1. Inside your docker-compose.yml file, add this to the volumes section of the desired container: /Users/[username]/docker/php/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

  2. Restart your docker container and it should show the new settings.

@intcreator
Copy link

the documentation mentions using docker exec to run common commands like occ. this solved the issue for me

@aguirre-ivan
Copy link

I modified the docker container php.ini file with 1024M but now I get Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes). What am I missing?

Running ini_get('memory_limit').PHP_EOL I check that memory_limit = 1024M, but it's still not working.

@gino8080
Copy link

gino8080 commented Jul 4, 2022

Also you can use the docker ENV var MEMORY_LIMIT
example

phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: pma
    links:
      - joomladb
    environment:
      PMA_HOST: joomladb
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
      UPLOAD_LIMIT: 300M
      MEMORY_LIMIT: 3000M
    restart: always
    ports:
      - 8081:80
      

@AndreyGladkikh
Copy link

you can also set memory_limit in etc/php-fpm.d/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants