WordPress.org

Ready to get started?Download WordPress

Forums

ALERT - script tried to increase memory_limit to 268435456 bytes which is above (26 posts)

  1. Ryan Cowles
    Member
    Posted 2 years ago #

    I have been experiencing significant lag and timeouts in the backend of one of my WordPress installs. I enabled error logs and am now seeing errors that keep showing line 109 in ../wp-admin/admin.php Here are two examples chosen at random:

    [Tue Apr 24 13:14:46 2012] [error] [client xx.xxx.xxx.xx] ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xx.xxx.xxx.xx', file 'path/to/file/wp-admin/admin.php', line 109), referer: http://www.DOMAIN.com/wp-admin/post.php?post=2276&action=edit
    [Tue Apr 24 13:24:10 2012] [error] [client xx.xxx.xxx.xx] ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xx.xxx.xxx.xx', file 'path/to/file/wp-admin/admin.php', line 109), referer: http://www.DOMAIN.com/wp-admin/options-general.php

    What could be causing these errors? And how can they be fixed?

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Try increasing the memory available to PHP. Or switching themes and deactivating some plugins.

  3. Ryan Cowles
    Member
    Posted 2 years ago #

    Thank you! I will try increasing the memory limit, but I would ideally like to identify what exactly the errors are stemming from.

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    From your theme and your plugins.

  5. Elan42.com
    Member
    Posted 2 years ago #

    I had the same problem, and even if I HAVE access to my apache+php configuration, I REFUSE to give to a php process 256 M of memory limit.

    Neither I want to change admin.php file because it will be overwritten every time I upgrade WordPress.

    Don't you guys think 256 it's too much ?

    Please go back to 128 in next versions, a php CMS should work with 32M of memory.

  6. Yes, and it does too. See the part about

    From your theme and your plugins.

    Just a plain installation of WordPress doesn't take up 128MB of RAM. But tack on memory hungry code from a theme and/or plugins? Those take lots of RAM and some add-ons are not well written memory use wise.

    If you can't allocate the additional RAM then use a different theme and plugins.

  7. Elan42.com
    Member
    Posted 2 years ago #

    But why we are talking about ../wp-admin/admin.php ?

    That memory allocation is not inside bad plugins / themes ...
    ... or am I wrong ?

  8. You're wrong, but that's OK. ;)

    The stock plain single-site WordPress running with the Twenty Eleven theme and no plugins doesn't use 128MB of RAM. I'm reasonably sure that 32MB is fine for that setup.

    But when you add plugins, themes, multisite, etc. then your memory requirements can increase too.

    I'm running multi-site with themes and plugins. On my primary site I'm running 16 active plugins.

    I set my memory_limit = 80M but I really don't need to above 64M (remember, I'm running multisite). I had a plugin which was eating all of my RAM but that's gone and I haven't had memory limit issues in months.

    My (rambling) point is: if you need more RAM allocate it. If you can't then start making decisions about the add-ons that you are using.

  9. Elan42.com
    Member
    Posted 2 years ago #

    Yes but my point is different, as a webmaster but also hosting provider, I don't want a CMS to have in it's code a function that, ON REQUEST, asks for 256 M of RAM.

    I don't care about how much themes and plugins my customers have activated, their websites have to FAIL to open and gives error if they go over my memory_limit in php.ini.
    This is why a memory_limit exists.

    So I'm asking you and WP developers to find a more flexible way to fix things, that could be a new option in wp-config like:
    define('WP_MEMORY_LIMIT', X);

    Where X is the maximum memory limit that WordPress will ask for a user that activate 2305982 plugins without caring about my server.

    p.s. this line 109 in admin.php can be the cause of MANY of my server crashes in this last months.

  10. So I'm asking you and WP developers to find a more flexible way to fix things, that could be a new option in wp-config like:
    define('WP_MEMORY_LIMIT', X);

    I'm not a developer (good thing too) and I'm sure you know that that option is already available.

    http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP

    p.s. this line 109 in admin.php can be the cause of MANY of my server crashes in this last months.

    Not sure what to say about that, that shouldn't cause any host to crash.

    An occasional warning in log file is just background noise. If it's filling up the disk space then you have an option to increase your memory limit or not use WordPress.

    WordPress may have different requirements but at the end of the day it's just another collection of PHP scripts.

  11. Elan42.com
    Member
    Posted 2 years ago #

    Ok, so the answer to give to the first poster was this:
    define('WP_MEMORY_LIMIT', '128M');

    And now it's a resolved topic.

  12. RavanH
    Member
    Posted 1 year ago #

    Hmmm... Running into this issue on a fresh WordPress 3.4.1 install that I've just converted to a Multi-site setup. Nothing installed other than bare WordPress so it does not seem to be related to 'themes or plugins'. And setting WP_MEMORY_LIMIT in wp-config.php to within the (in my opinion reasonable) 64M limit on the server, does not fix the issue.

    Why would WordPress even be ask for such a high memory limit??? I'm pretty sure it only needs about 40M at the most. And running APC on the server, it is usually half that number.

  13. jruberto
    Member
    Posted 1 year ago #

    The OP's error / alert is from Suhosin. Suhosin "protects" PHP with a very restrictive set of rules.

    Certain plugins might need more memory (i.e. image processing scripts), and therefore attempt to increase the memory available -- and Suhosin doesn't permit that.

    When Suhosin disallows something it just silently fails, it doesn't cause a runtime PHP error, and it only logs to syslog. Usually the symptom is you try to do something, it looks like it worked, and then you reload the page and it didn't work.

    Yes, the proposed solutions (changing PHP's memory limit on-the-fly) would CAUSE this error on a Suhosin-protected server.

    Anyway, philosphical arguments aside, the fix is to make sure suhosin is configured for:
    suhosin.memory_limit = 256M

  14. RavanH
    Member
    Posted 1 year ago #

    Thanks jruberto, that did indeed solve the issue without increasing the PHP memory_limit to 256M in php.ini

    And thanks for the clear explanation on Suhosin :)

    One interesting question remains: why and when would the WP admin need 256M? It certainly is not needed for normal operations. Maybe on a multi-site install when upgrading or something? And why not only try to increase the memory_limit at such a point instead of doing that all the time?

  15. Jerry_S
    Member
    Posted 1 year ago #

    Actually WP_MEMORY_LIMIT is the wrong parameter (it defaults to 32M/64M for single/multiple sites). The one you want is WP_MAX_MEMORY_LIMIT, which defaults to 256M.

  16. Elan42.com
    Member
    Posted 1 year ago #

    Thank you for the great fix.

  17. jruberto
    Member
    Posted 1 year ago #

    One interesting question remains: why and when would the WP admin need 256M?

    It looks like in file.php, WP attempts to max out allocated memory before it unzips a zip file. From the comments:

    * Attempts to increase the PHP Memory limit to 256M before uncompressing,
     * However, The most memory required shouldn't be much larger than the Archive itself.

    It uses WP_MAX_MEMORY_LIMIT to do this so I suppose the most correct advice is to make sure that suhosin.memory_limit is equal to or greater than WP_MAX_MEMORY_LIMIT (which is 256M by default)

  18. RavanH
    Member
    Posted 1 year ago #

    ... or lowering WP_MAX_MEMORY_LIMIT to the same level as the default WP_MEMORY_LIMIT with

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

    in wp-config.php because when would one actually make WordPress unzip an archive larger than that? Or are there any plugins or themes out there that huge? ;)

  19. planetzuda
    Member
    Posted 1 year ago #

    Okay, any plugin or theme that is using 128 megabytes is doing something very fishy. It was probably doing more than you could see. I'd love to read that code. Ravan, 64 megabytes should become the normal memory limit for WordPress in the near future.

  20. RavanH
    Member
    Posted 1 year ago #

    Planetzuda, it's not any plugin (in particular) asking for such a high memory limit, it's WordPress itself. Notably in admin.php and file.php... Although you are rightfully suspicious about plugins that need a lot of memory, there are some that do need a lot for their operations (like loading a lot of posts at the same time for instance) without being malicious.

    Of course one could discuss more efficient ways to approach things in particular cases but generally speaking, asking for a higher memory limit when it is actually needed, is not intrinsically bad. Any plugin, which is essentially just another set of PHP scripts, can negotiate it's own memory limit within the PHP environment but run into restrictions set in php.ini or by (as jruberto explained) Suhosin. It's up to the host to set these hard limits on the server.

    What surprises me is the fact that the WordPress admin asks for 256M by default, even when it does not need to... And I wonder when it ever will need 256M.

  21. planetzuda
    Member
    Posted 1 year ago #

    RavanH, I just dealt with an issue like this 4 hours ago. It was complaining that it was the wordpress admin page, but it wasn't. It was a camera plugin. The second the plugin was removed everything went back to normal. My gut instinct is telling me that this site doesn't need 128 megabytes for the wordpress admin. I believe it is a poorly designed plugin. If it is designed to be a memory hog, then it probably has an exploit as well. Of course, these are only educated guesses on what I've seen and fixed.

    I too am surprised that file.php is set by default to use 256 megabytes. Why would you want such a big plugin.. WordPress updates are never that big.

  22. jruberto
    Member
    Posted 1 year ago #

    What surprises me is the fact that the WordPress admin asks for 256M by default, even when it does not need to... And I wonder when it ever will need 256M.

    It's sensible for file.php to allocate as much memory as it can (and know that the comment from the code is incorrect, it asks for WP_MAX_MEMORY_LIMIT, not 256M) -- realize that in many hosted environments WP_MEMORY_LIMIT as well as WP_MAX_MEMORY_LIMIT are both going to be clamped way down, and an image-heavy theme .zip file could perhaps be larger than WP_MEMORY_LIMIT.

    But in any case, if WP_MEMORY_LIMIT is smaller than WP_MAX_MEMORY_LIMIT, file.php or any other script that tries to allocate more memory will cause suhosin to throw the alert the OP experienced and disallow the operation.

    see http://www.hardened-php.net/suhosin/configuration.html#suhosin.memory_limit
    at its default "...disallows setting the memory_limit to a value greater than the one the script started with..."

    Seems sensible to put WP_MEMORY_LIMIT at a nominal value for usual site operation, and then set WP_MAX_MEMORY_LIMIT as well as suhosin.memory_limit to the high water mark for memory intensive scripts.

    And none of these WP_ constants will stop a malicious script from allocating as much memory as it wants -- that's what suhosin is for. :)

  23. planetzuda
    Member
    Posted 1 year ago #

    I want to make it very clear that I never said a WP_ constant would stop a malicious script. All I was meaning to say was that a malicious script may use more memory. A non-malicious script can also use a lot of memory, but WordPress using 128 megabytes is hard to fathom. It must have a lot of plugins running and a huge theme.

  24. D. G.
    Member
    Posted 1 year ago #

    The annoying message: "ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value..." is generated every time a admin page is asked. After logon the admin page the first issue is there. All other pages within the default 'admin' site a message is generated.
    Increasing memory assignment to PHP did NOT solve this.
    Other changes to WP_MAX_MEMORY_LIMIT, WP_MEMORY_LIMIT or so did NOT changed anything.
    The admin page seems to run fine though, but the messages keep being sent to the syslog. Every time i enter/change a admin page, a message keeps generated, very annoying for a machine with Intel(R) Xeon(TM) CPU 3.20GHz, 2 cores, 4 GB RAM, running Linux Debian 6.0.5 with Webmin and WordPress.
    Anyone has a REAL sollution as nothing i read seems to work.

    Regards, DG.

  25. planetzuda
    Member
    Posted 1 year ago #

    errors, alerts, warnings, etc from PHP should not be shown on the site. That is a vulnerability in itself. A script is trying to increase the memory to 268 megabytes, which is above the default maximum memory limit of 256 megabytes. I retract my previous statements saying that 256 megabytes is too large to have as a default maximum memory limit.

    The warning you are getting is suhosin trying to protect the server like jruberto mentioned a few months ago.

  26. D. G.
    Member
    Posted 1 year ago #

    I changed yesterday all paramaters to 64M (i.e. WP_MAX_MEMORY_LIMIT, WP_MEMORY_LIMIT, etc).
    Today the error is NOT generated anymore in syslog when entering admin pages :)

Topic Closed

This topic has been closed to new replies.

About this Topic