52

I'm getting an error when I try to open one of my dashboard pages in my wordpress script

The error message is as follows:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes) in /home/admin/domains/filesick.com/public_html/wp-includes/taxonomy.php on line 2685

I asked around and was told I have to increase the memory_limit to something higher than 256M, so I changed it to 512M and still the same problem. Then I changed it to 3024M and this is what I have now, but that didn't fix the problem.

So could you please tell me how to fix this and what should I do?

Waiting for your response.

Loopo
  • 2,204
  • 2
  • 28
  • 45
Tarek Ezzat
  • 535
  • 1
  • 5
  • 8
  • 1
    It sounds like your memory limit change is not being applied. You might be editing the wrong file. Try to run php_info() in a script in the same directory as your wordpress installation, and check the output for the actual memory_limit there. – Loopo Feb 10 '14 at 14:58
  • 2
    At a guess, you've got some code that's causing an infinite loop – andrewsi Feb 10 '14 at 14:58
  • Instead of increasing memory, I'd fix the dashboard and remove everything unnecessary.. – Daniel W. Feb 10 '14 at 14:59
  • well it's not my code it's the coder that i paid him to do the whole site and he said that it's not his code it;'s the server that i should check – Tarek Ezzat Feb 10 '14 at 15:00
  • tell him to fix it and make the scripts use less resources or don't pay him honestly wtf 250MB of data for a dashboard do you know how much data this is... – Daniel W. Feb 10 '14 at 15:02
  • @Loopo could you please give me instructions on how to do that and i am opening the php.ini file i'm sure and i save using the ctrl+o – Tarek Ezzat Feb 10 '14 at 15:02
  • actually, as andrewsi suggested there may be a problem in the program, does the ``allowed memory size of xxxx`` error change when you change the limit? that would indicate that all the memory is being consumed, no matter how much you increase it by – Loopo Feb 10 '14 at 15:06
  • no @Loopo it doesn't it's always 268435456 bytes does that say something ? – Tarek Ezzat Feb 10 '14 at 15:13
  • 2
    That means the memory limit isn't being changed by your edits. This can have various causes, but there is a setting in wp-config.php ``define("WP_MEMORY_LIMIT", 512);`` – Loopo Feb 10 '14 at 15:28

3 Answers3

67

WordPress overrides PHP's memory limit to 256M, with the assumption that whatever it was set to before is going to be too low to render the dashboard. You can override this by defining WP_MAX_MEMORY_LIMIT in wp-config.php:

define( 'WP_MAX_MEMORY_LIMIT' , '512M' );

I agree with DanFromGermany, 256M is really a lot of memory for rendering a dashboard page. Changing the memory limit is really putting a bandage on the problem.

Sven
  • 1,450
  • 3
  • 33
  • 58
Dave Ross
  • 3,313
  • 1
  • 24
  • 21
  • thank you so much Dave it works but please what does that mean where is the issue like what is the reason that lead to this problem the coder or the server ? – Tarek Ezzat Feb 10 '14 at 15:43
  • It depends on what the code is doing, there could be a legitimate reason for having to use so much memory, e.g. processing large files, but even for large files, instead of reading the whole thing into memory there can be a way to process it in chunks. – Loopo Feb 11 '14 at 08:48
  • 1
    Sometimes it's the platform itself. For example in the WordPress (3.8.3) code /wp-includes/wp-db.php starting on line 1240 there is a loop that is supposed to accumulate the results of a database query into an array. This failed for me at around 26,800 posts. Now I cannot tell why the WordPress team chose to load all the posts in one call, but the admin dashboard fails as a result of this. – KalenGi Feb 27 '15 at 11:00
  • @dave What is the difference? 'WP_MEMORY_LIMIT' – borayeris May 29 '16 at 23:58
  • 2
    @borayeris WordPress assumes the admin section will use more memory, so WP_MEMORY_LIMIT controls the maximum memory available normally, while WP_MAX_MEMORY_LIMIT sets the maximum just on admin pages. It's a terrible naming scheme but it dates back to WordPress 2.5 and nobody dares change it now. See http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP – Dave Ross May 30 '16 at 02:57
20

I had this problem. I searched the internet, took all advices, changes configurations, but the problem is still there. Finally with the help of the server administrator, he found that the problem lies in MySQL database column definition. one of the columns in the a table was assigned to 'Longtext' which leads to allocate 4,294,967,295 bites of memory. It seems working OK if you don't use MySqli prepare statement, but once you use prepare statement, it tries to allocate that amount of memory. I changed the column type to Mediumtext which needs 16,777,215 bites of memory space. The problem is gone. Hope this help.

user3707094
  • 331
  • 2
  • 4
  • 1
    This is what was causing my PHP app (laravel) to allocate more than 256M - the jobs table (automatically created by Laravel for queueing) contains a LONGTEXT! I changed it MEDIUMTEXT (16MB, more than sufficient) – Leon Jan 03 '22 at 20:11
7

I changed the memory limit from .htaccess and this problem got resolved.

I was trying to scan my website from one of the antivirus plugin and there I was getting this problem. I increased memory by pasting this in my .htaccess file in Wordpress folder:

php_value memory_limit 512M

After scan was over, I removed this line to make the size as it was before.

Chinmay Atrawalkar
  • 942
  • 1
  • 8
  • 6