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?

Read More

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

Related posts

Leave a Reply

6 comments

  1. 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

  2. There are @ini_set('memory_limit', '256M'); before images are loaded in memory by GD functions.

    imagecreatefromstring() (line 253, wp-includes/media.php) is used by wp_load_image() which is used by image_resize (the function were the images processing is done for thumbnails creation).
    The memory limit is at line 252, so, as far as I can see, there is no way to do modify it without killing a kitten* >:).

    There are also GD functions in load_image_to_edit() (line 200, wp-admin/includes/image-edit.php). This one is used by the image editor (I neved used it, since I know WordPress, didn’t even know were to find it :)). If your client use it, you may want to set the memory limit there also. There is the filter load_image_to_edit_path.

    Hope my answer is helpful.

    *hacking core

  3. Swill – I had just same problems. Damn wordpress with some of the “features”
    A rather more sophisticated approach is to change all the @ini_set ‘s to set it from WP_MEMORY_LIMIT – problem solved

    Also, changing php values at runtime ain’t that smart, not sure why it is implemented 🙁

  4. By your description I think this code in admin.php is the issue:

    if ( current_user_can( 'manage_options' ) )
        @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
    

    Somewhat strange that it treats admin memory usage separately, but at least it is filterable.

  5. I just wanted to say thanks to bangbambang. This is the first post I found that was able to give me some insight into why the entry into wp-config.php of define('WP_MEMORY_LIMIT', '512M'); was not actually being used. I spent hours trying to figure this out…

    My import was failing with the 256M exhausted issue regardless of how I set the memory limit.

    Here are the places where the memory limit is hardcoded to 256M (in version 3.0.5 anyway).

    wp-admin/includes/file.php (line 532)
    
    wp-admin/includes/image-edit.php (line 393 & 498)
    
    wp-includes/media.php (line 252)