Can't increase php limit of cnextcloud cron job (and want to understand why limit is reached)

Nextcloud version (eg, 20.0.5): 25.0.3
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.41
PHP version (eg, 7.4): 8.1

The issue you are facing:

When running the nextcloud cron job, I see the following in the log:

CRON[1083249]: (www-data) CMD (PHP_MEMORY_LIMIT=3000M cronic php -f /var/www/nextcloud/cron.php)
Feb 14 12:45:44 ed-mh-x86001 Nextcloud[1076417]: {"reqId":"1enS1bxafYGtQvM53sCv","level":3,"time":"2023-02-14T12:45:44+00:00","remoteAddr":"","user":"<redacted_user_name>","app":"PHP","method":"PROPFIND","url":"/remote.php/dav/files/<redacted_user_name>/Field-Data/wind/<redacted>/<redacted>/2021","message":"Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) at /var/www/nextcloud/lib/private/L10N/Factory.php#129","userAgent":"Mozilla/5.0 (Windows) mirall/3.4.1stable-Win64 (build 20211221) (Nextcloud, windows-10.0.19045 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"","data":{"app":"PHP"}}

The folder in question <redacted_user_name>/Field-Data/wind/<redacted>/<redacted>/2021 contains thousands of very small files. The root folder (Field-Data) is an external folder on a linux SMB share, and is read-ony.

I’ve tried really hard to increase the php memory limit to 3000M, by changing memory_limit in the following files:


(I have set up HTTP2 and am therefore using php-fpm).

And also modifying the call to php in the cron job line, as you can see above, by trying to set the PHP_MEMORY_LIMIT environment variable. It still hits the memory limit at 1073741824 bytes.

In all the above files I have also set apc.enable_cli=1, and have also added it to the following files.


In case it’s relevant I’m using the Client Push app.

My question is, how can I increase the memory limit, and separately what is the real root cause of this error?

Is this the first time you’ve seen this error? (Y/N): Y (first time I’ve noticed)

The output of my config.php file):

$CONFIG = array (
  'passwordsalt' => ''<redacted>',
  'secret' => ''<redacted>,
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '<redacted>',
    2 => 'nextcloud.<redacted>',
  'datadirectory' => '/mnt/'<redacted>/nextcloud-data',
  'dbtype' => 'mysql',
  'version' => '',
  'overwrite.cli.url' => 'https://'<redacted>',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => ''<redacted>',
  'installed' => true,
  'instanceid' => ''<redacted>',
  'maintenance' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis-server.sock',
    'port' => 0,
    'password' => ''<redacted>',
    'timeout' => 1.5,
  'mail_from_address' => 'nextcloud',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => ''<redacted>',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => ''<redacted>',
  'mail_smtpport' => '465',
  'mail_smtpname' => ''<redacted>',
  'mail_smtppassword' => ''<redacted>',
  'mail_smtpsecure' => 'ssl',
  'theme' => '',
  'log_type' => 'syslog',
  'syslog_tag' => 'Nextcloud',
  'logfile' => '',
  'loglevel' => 3,
  'ldapIgnoreNamingRules' => false,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'mysql.utf8mb4' => true,
  'default_phone_region' => 'GB',
  'trusted_proxies' => 
  array (
    0 => '',
    1 => '::1',
    2 => '<redacted>',
  'overwriteprotocol' => 'https',


Setting the cron command to be

PHP_MEMORY_LIMIT=3000M cronic php -d memory_limit=3000M -f /var/www/nextcloud/cron.php

seems to have gotten rid of the error for me, but I still would like to kno why the other things didn’t work in case there is something I’m missing.

Php-CLI should be the right one to use. However two concerns: you use the known elv path for php. Are you certain it then executes as the right php version?

On a CLI, what is the output of:
Php - v ?

output is

$ php -v
PHP 8.1.14 (cli) (built: Jan 13 2023 10:43:22) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.14, Copyright (c), by Zend Technologies

however, I specifically removed all php 7.4 and installed php 8.1 from the dev PPA.

Okay that is good.

Try setting the memory limit to -1 only for the cli version of php and run the php commands again clean without pre set prarmeters