Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress 2MB memory limit coming from nowhere

I have just downloaded a fresh new WordPress to a virtual server where a WP and MediaWiki are already running smoothly. The memory_limit in php.ini is set to 256MB. But for some reason WP thinks it is limited to only 2MB, see Apache log entry below.

[Sun Nov 19 08:50:21.692866 2017] [:error] [pid 74814] [client 109.81.213.117:59968]
PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate
131072 bytes) in /var/www/foo.bar/subdomain/wp-includes/capabilities.php on line 452

When I print phpinfo() from the index.php file of my new WP, it shows the 256MB limit so there is no second secret php.ini configuration for this subdomain or directory.

I also tried to find a mischievous setting of memory limit in .htaccess or php file but with no avail. (grep -r "memory_limit" .)

Any ideas where this 2MB limit could be coming from?

UPDATE

I put ini_get('memory_limit'); exit; in the middle of wp-settings.php where it is including other files. Sometimes it writes the 256MB as it is supposed to, sometimes it dies in /var/www/iurium.cz/daily/wp-includes/wp-db.php with the error of 2MB. The behavior is quite random.

What else can influence the memory limit if not htaccess, php.ini or ini_set? Does it have to do with PHP at all? Can it be set in the system somehow?

like image 833
Ondrej Henek Avatar asked Nov 19 '25 17:11

Ondrej Henek


2 Answers

Make sure your memory_limit value is 256M (not 256MB).

The PHP description of resource limits calls for 256M https://www.php.net/manual/en/ini.core.php#ini.memory-limit

You can use phpinfo() or ini_get('memory_limit') to check the value.

If memory_limit doesn't match the expected format, PHP will default to 2M (2097152 bytes)

like image 137
jakxnz Avatar answered Nov 21 '25 08:11

jakxnz


Having the same problem. No idea what's causing it. Alleviated it by using @ini_set('memory_limit', '512M'); in wp-config.php

Some plugin (or theme file) is changing memory_limit somewhere.

like image 40
NolePTR Avatar answered Nov 21 '25 06:11

NolePTR