docker icon indicating copy to clipboard operation
docker copied to clipboard

Memory limit quite low

Open nalt opened this issue 9 years ago • 30 comments

The php memory_limit is not set and thus defaults to 128M. This results in a crash, when I try to generate thumbnails of photos taken with a standard digital camera usingocc preview:generate-all.

A larger memory limit is required for this standard task. It should be ok to increase it on installations that target only small groups of users.

Possible solutions:

  • Explicitly set (a larger) memory_limit in Dockerfile
  • Allow to set the memory limit with an ENV var
  • Add a php-override.ini and document how to use it. Advantage: This would allow for all kinds of custom tweaks to php.ini

nalt avatar Nov 14 '17 15:11 nalt

@kjlhgfds I found this in my custom dockerfile that might help

echo 'memory_limit=2G' > /usr/local/etc/php/conf.d/memory-limit.ini

FriedCircuits avatar Oct 17 '18 04:10 FriedCircuits

Hi, there's a way without touching the image at all. In my docker-compose.yml there are two lines in the volumes: section allowing container specific configuration.

      - ./etc/php-fpm.d/www.overloaded.conf:/usr/local/etc/php-fpm.d/www.overloaded.conf
      - ./etc/php/conf.d/nextcloud.ini:/usr/local/etc/php/conf.d/nextcloud.ini

The file www.overloaded.conf is for overloading some values in the fpm module as I want to set my own server values. The default values in the image are set in a file called /usr/local/etc/php-fpm.d/www.conf and as the files in php-fpm.d/ are evaluated in alphabetic order I chose www.overcload.conf to make sure its read afterer www.conf.

[www]
pm = dynamic
pm.max_children=100
pm.start_servers=10
pm.min_spare_servers = 4
pm.max_spare_servers = 10
;pm.process_idle_timeout = 10s;
;pm.max_requests = 1000

nextcloud.initakes care of the memory settings and some other php settings.

[PHP]
memory_limit = 8G
upload_max_filesize= 10G
post_max_size = 11G
max_execution_time = 3600
max_input_time = 3600

Because both files are located in a local directory it's very easy to change them. As soon as the container is restarted they are effective. No image generation required.

Hope that helps.

lhurt avatar Oct 17 '18 08:10 lhurt

@lhurt the trick with the memory_limit setting in the nextcloud.ini sets for me the memory_limit on the "global" php level, whereas the "local" level is overwritten by the .htaccess file which has:

<IfModule mod_php7.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 512M
  php_value mbstring.func_overload 0
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>

If I comment the memory limit in the .htaccess, then it works as expected, but this is still a manual workaround. How have you solved that? I am useing the nextcloud:14-apache image

kosli avatar Nov 05 '18 19:11 kosli

@lhurt the trick with the memory_limit setting in the nextcloud.ini sets for me the memory_limit on the "global" php level, whereas the "local" level is overwritten by the .htaccess file which has:

<IfModule mod_php7.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 512M
  php_value mbstring.func_overload 0
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>

If I comment the memory limit in the .htaccess, then it works as expected, but this is still a manual workaround. How have you solved that? I am useing the nextcloud:14-apache image

No. I'm using the nginx php-fpm image combination.

Sorry.

You could try to supersede the .htaccess file in the docker-compose.yml by adding - <path to your local .htaccess file>:/var/www/html/.htaccess. The downside is that you have to copy and edit the .htaccess file from the distribution every time. Otherwise consider a change the webserver.

Hope that helps.

ludwighurt avatar Nov 06 '18 09:11 ludwighurt

A solution has been posted in https://github.com/nextcloud/docker/issues/182#issuecomment-430531984, so I'll close this.

J0WI avatar Nov 04 '19 22:11 J0WI

My allowed memory size is 2 GB, but I still get this error for allocating just 16 MB.

PHP Fatal error: Allowed memory size of 2,147,483,648 bytes exhausted (tried to allocate 16,059,048 bytes) in /var/www/html/lib/private/legacy/OC_Image.php on line 649

Why does this happen?

MichaelUray avatar Jul 06 '20 22:07 MichaelUray

you don't need to override the entire nextcloud.ini anymore, there is a separate file for memory limit, its called memory-limit.ini

make sure to create a file called memory-limit.ini to mount into, just put memory_limit=4G inside it

and then add this under the volumes section in docker-compose

- ${NEXTCLOUD_ROOT}/php/memory-limit.ini:/usr/local/etc/php/conf.d/memory-limit.ini

FarisZR avatar Feb 18 '21 17:02 FarisZR

@fareszr That's nice, is it documented somewhere so I can get more info about it?

This is my docker container situation:

root@76abe3b16f2a:/usr/local/etc/php/conf.d# cat nextcloud.ini memory_limit=${PHP_MEMORY_LIMIT} upload_max_filesize=${PHP_UPLOAD_LIMIT} post_max_size=${PHP_UPLOAD_LIMIT} root@76abe3b16f2a:/usr/local/etc/php/conf.d# echo ${PHP_MEMORY_LIMIT} 512M

setting that file memory-limit.ini would override the env variables referenced by nextcloud.ini?

robertofabrizi avatar Feb 25 '21 08:02 robertofabrizi

@fareszr That's nice, is it documented somewhere so I can get more info about it?

This is my docker container situation:

root@76abe3b16f2a:/usr/local/etc/php/conf.d# cat nextcloud.ini memory_limit=${PHP_MEMORY_LIMIT} upload_max_filesize=${PHP_UPLOAD_LIMIT} post_max_size=${PHP_UPLOAD_LIMIT} root@76abe3b16f2a:/usr/local/etc/php/conf.d# echo ${PHP_MEMORY_LIMIT} 512M

setting that file memory-limit.ini would override the env variables referenced by nextcloud.ini?

after investigating further, i think its better to just replace it directly in nextcloud.ini. becuase as you said memory_limit.ini doesn't change the php variable

FarisZR avatar Feb 25 '21 19:02 FarisZR

You can simply set the environment variable PHP_MEMORY_LIMIT for your docker container (for instance "PHP_MEMORY_LIMIT=2G"). PHP_UPLOAD_LIMIT is also available to set the max size of files to be uploaded.

inquam avatar Mar 29 '22 13:03 inquam