Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
hey, haven't seen you in a while. Guess you've been busy with clients; good for you! Have you considered maybe offloading the image processing, maybe using Amazon S3 and EC2? aws.amazon.com/articles/1602 Or Google App Engine? code.google.com/appengine/docs/python/images/usingimages.html Or using urlimg.com? –  MikeSchinkel Oct 26 '10 at 10:02
    
@MikeSchnikel - Hej! I'm looking to solve this with wordpress. If I need to setup a thumbnail server I wouldn't use wordpress anyway so. But thanks for the links, very interesting at least :). –  hakre Oct 26 '10 at 10:20

5 Answers 5

up vote 10 down vote accepted

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) :D

edit 2:

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

share|improve this answer
2  
+1 just because I laughed out loud at your edit. Nice. –  goldenapples Oct 29 '10 at 17:29
    
your answer is far away from being stupid. To be precise it was kinda stupid of me posting this question while I already knew the answer, and your comment totally shows that you factually ran over that. Really, my bigest apologies, posting the link here was so right as far as I knew myself while posting the question, so what to say? Thanks for being that open to admit that! I like your style and linked my blog to your answer (not only linked back to the blog). –  hakre Feb 13 '11 at 1:32
    
In 3.2 this should be configurable: Changeset 17749 –  hakre May 4 '11 at 23:29

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

share|improve this answer
    
Yup, these are hardcoded into a few admin-side functions relating to images. There is a WP_MEMORY_LIMIT constant and even an admin_memory_limit filter, but neither are consulted in these handful of cases. –  Annika Backstrom Oct 26 '10 at 12:56

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 :(

share|improve this answer

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.

share|improve this answer
    
This does not work for the image operations in the admin. They get reduced to 256MB again regardless if I use that filter or not. :/ –  hakre Oct 26 '10 at 10:17

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)
share|improve this answer
    
Ticket #13847 has a patch attached that makes those places configure-able with an additional constant called WP_MAX_MEMORY_LIMIT. –  hakre Feb 9 '11 at 22:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.