How to use more than 256MB of memory in the admin?

I’m building a site for a photographer who uploads pictures that are normally large for todays digital cameras. Images are quite memory intensive, especially the image operations like creating thumbnails.

So I wanted to raise the memory limit in the admin above 256MB – how can this be done? I allowed CGI and PHP to use up to 1 Gigabyte but wordpress always decreases the memory to 256MB. Any idea how to fix that on a client side that needs to be able to auto-update?

UPDATE: From WordPress 3.2 ongoing the maximum memory limit in WordPress will be configure-able again.

6 s
6

Theoretically, editing your config.php and add this line before wp-settings.php inclusion.

define('WP_MEMORY_LIMIT', '256M');

should raise your memory limit for WordPress to 256MB or whatever value you set. And this will work sitewide. However, as sorich87 pointed out, there are few functions that will alter this setting with hard coded 256 MB limit.

To Hack or Not To Hack

A little concern about this, WP_MEMORY_LIMIT is one of the most strange WP setting I’ve encountered. if you check /wp-includes/default-constants.php you’ll find this setting:

// set memory limits
if ( !defined('WP_MEMORY_LIMIT') ) {
    if( is_multisite() ) {
        define('WP_MEMORY_LIMIT', '64M');
    } else {
        define('WP_MEMORY_LIMIT', '32M');
    }
}

I never realize that WP will set it’s default memory usage so low, until I find this in WP codex:

WordPress will automatically check if PHP has been allocated less memory than the entered value before utilizing this function. For example, if PHP has been allocated 64MB, there is no need to set this value to 64M as WordPress will automatically use all 64MB if need be.(source)

That explanation was relieving. However, the usage of hard coded @ini_set('memory_limit', '256M'); everytime WP execute function that need more memory is never mentioned. In fact, I find no explanation about this vague behavior from WP codex. Since most of non user-related functions are either not documented or not clearly explained in codex.

While this setting work nicely on most case, it will make those functions useless on server with lower max memory setting or on your case, higher memory usage.

Until WP guys fix this, I think your only solution is to modify the core. You may find this post written by hakre interesting to read. He also submit a patch recommendation in Trac. Previous link to patch file may help you to find list of function that use this setting.

edit:

this is the most stupid answer I’ve ever give because I give a link to your own post (just realize that OP name was hakre after 2 days) 😀

edit 2:

as mentioned on comment, this has been fixed by 3.2 release

Leave a Comment