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.
Theoretically, editing your config.php and add this line before wp-settings.php inclusion.
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:I never realize that WP will set it’s default memory usage so low, until I find this in WP codex:
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
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 bywp_load_image()
which is used byimage_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 filterload_image_to_edit_path
.Hope my answer is helpful.
*hacking core
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 🙁
By your description I think this code in
admin.php
is the issue:Somewhat strange that it treats admin memory usage separately, but at least it is filterable.
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).