Error when running the preview generator: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 77824 bytes) in /config/www/nextcloud/lib/private/legacy/OC_Image.php on line 533

I’m running Nextcloud v26 as a container on an Unraid server together with Redis.
Parts of the config.php looks like this:

$CONFIG = array (
‘memcache.locking’ => ‘\OC\Memcache\Redis’,
‘memcache.local’ => ‘\OC\Memcache\Redis’,
‘redis’ =>
array (
‘host’ => ‘redis’,
‘port’ => 6379,
‘password’ => ‘nopey’,
),

I try to run this command from inside the container
occ preview:generate-all

But after a while it throws the error:
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 77824 bytes) in /config/www/nextcloud/lib/private/legacy/OC_Image.php on line 533

Not sure where to start tbh.
Some other threads have mentioned setting apc.enable_cli=1, but it seems to been done, inside the file /etc/php81/conf.d/apcu.ini

I also get errors every time I try to upgrade Nextcloud. Times out every time. Maybe it’s related?

EDIT:
Tried to change
‘memcache.local’ => ‘\OC\Memcache\APCu’,

But unfortunately, no difference :confused:

Your system is low on memory. 512 MB is the minimum requirement, if you have installed too many apps, that can easily trigger such a problem. Also to consider, if you are at the minimum requirement, you need to adjust all your services to be as efficient as possible (database, webserver, …), that can be tricky since the best configuration can depend on the use case.

Generating thumbnails takes up some resources:

There was a great blog post from NextcloudPi, I can’t find it any more.

But… Nextcloud is running as a container on a host that has plenty of memory, and nowhere near using it all.
Is there some kind of memory limit for docker containers that I’ve never heard of maybe?

It would make sense to limit the resource usage, for other virtual machines you can configure that. I don’t use docker, but your favorite search engine can probably help you.

Does anyone that actually uses docker have an answer for this?

Thanks

@GD-Dal For my setup it was enough to slightly increase the memory limit for the command using php -d memory_limit=1024M occ .... With this you don’t alter your container configuration and can fine tune the limit.

1 Like

This comment is underrated! I searched quite some time, and for occ recognize clustering this was the best solution, to at least increate the batch size from 300 to 2000. Thanks!

The default PHP memory allocation is 512Mb under my docker container image (nextcloud:apache-stable).
This is not enough for all use cases - I hit problems with an inbound webdav connection from Photoprism - but the same PHP Error message.

Resolved the problem by setting the PHP_MEMORY_LIMIT to 1GB.
So added :
environment:
PHP_MEMORY_LIMIT: 1G
into my docker-compose yml file and restarted the container.

1 Like

Solved for me by adding a new variable. Thank you.

1 Like

I had the problem again, forgot I had the solution, looked online and found my own comment. LOL. Truly underrated :rofl:

1 Like