Increase PHP Memory Allowance Using ini_set()
On rare occasion, I need to up the memory allowed for PHP. Usually it's when I deal with large files and don't necessarily care about optimizing the file reading process but simply getting the file opened. There's an easy way to increase to amount of memory allowed to PHP right in your script:
ini_set('memory_limit','16M');
The above code will increase the maximum amount of memory available to PHP to 16 MB. Again, the setting is only adjusted for the running script.
One of the web components I've always loved has been Facebook's modal dialog. This "lightbox" isn't like others: no dark overlay, no obnoxious animating to size, and it doesn't try to do "too much." With Facebook's dialog in mind, I've created LightFace: a Facebook lightbox...
How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps?
This article serves as a point-by-point...
I was incredibly happy when CSS text-overflow: ellipsis
(married with fixed width
and overflow: hidden
was introduced to the CSS spec and browsers; the feature allowed us to stop trying to marry JavaScript width calculation with string width calculation and truncation. CSS ellipsis was also very friendly to...
One major gripe that we've always had about CSS is that creating layouts seems to be more difficult than it should be. We have, of course, adapted and mastered the techniques for creating layouts, but there's no shaking the feeling that there should be a...
I had to do this recently for a client who had joomla (yuck) installed. I just posted this in the top of their main index.php file so it was loaded on every page. It’s really good as a quickfix if you’re using something like Gallery or Joomla along with php-cgi, since php-cgi doesnt let you use htaccess.
Thank you o-b-wan, both for this post, and the kindly remonstration given on the other post that sent me here.
:)
Michael
This worked great David.
I had to place it below some other “session_start();” code in the index2.php file of a troublesome joomla installation, but it worked just as you offered.
memory_limit Local 16M; Master 8M
Thanks again o-b-wan.
Off to look for the next pebble…
:)
Michael
I have a problem with wordpress installing plugins where I get the error:
Which file should I place the code in? And I obviously need to increase it past 16MB so can I just put in:
maybe wp-config.php or the actual plugin? wp-postrating.php?
I cannot install plugins on wordpress due to a memory error.
I can’t get to php.ini, which file do you know should I put
ini_set(‘memory_limit’,’24M’)
in?
wp-config, the plugin script or all the wp php files?
thanks!
@Sam: You have to put
this line of code in the file/page, which on calling gives the error.
I’ve got a strange behaviour on PHP 5.2.11.
The php.ini set the memory_limit to 128MB. I can adjust the limit to 64M but never above the limit of 128M.
Did someone noticed a similar problem?
I tried to install wordpress 3.0.1 and i received this message : Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2966269 bytes) in /home/blidaru/public_html/wp-includes/http.php on line 1364
What i have to do?
put this on top of your http.php file
if that didn’t worked out try increasing 32M until it works for you
ini_set('memory_limit', '-1');
will be a neat solution as well. but I am still not sure of any side effects of this!Dangerous!
If you happen to have any flaw in your code, this could cause your server to become unresponsive.
Setting the memory_limit to -1 (infinite) should only be done for testing purposes on non-production machines!
You really save my life!!!
I was trying to work on local with prestashop 1.7, and nothing works for backoffice access products…
That’s was the solution!
Life saver, as always David.
Host of my dedicated saw fit to lower all max memory across their entire network for “security reasons”. Screw em, Big Daddy Walsh has my answer!
this is the best solution step by step
http://core.trac.wordpress.org/attachment/ticket/13847/13847.patch
Tried, didn’t work…
Thanks David but it didn’t work in my case – I think my host has put a limit on memory access – had an image resizing script with imagecreatetruecolor() – and script just would not go past it.
Set the memory limit to infinity then
set
ini_set(“memory_limit”,”128M”);
Here are 3 ways on how to increase it
http://newexception.com/php-increase-memory-limit
I need to put this in php.ini file or .htaccess file ?
@samily .htaccess is important in main folder (public_html) not in php.ini
Great works I just added and it works.
Just so you know, the administrator CAN limit your ability to increase this limit! There’s such a thing called PHP Safe Mode, and in this mode you can set function calls that will NOT be executed, no matter who calls them or from where. One of these functions can be
ini_set()
, which would block it completely.You can also try setting it via .htaccess, but that doesn’t always work (it hinges on ALLOW OVERRIDES being set to something other than NONE, I believe).
Keep that in mind. Sometimes, the only valid solution is to change your host.
Hi David,
I’m trying this right now. Somehow from php.ini it’s already 512M. In wp_config.php I also put
define('WP_MEMORY_LIMIT', '512M');
but somehow it keep getting 256M.I decided to use the
ini_set('memory_limit','1024M');
in my php file to see if it has any improvement. So far it’s not breaking due to memory limit yet.So thank very much for pointing this out.
“The above code will increase the maximum amount…” or decrease…
Just add this line in wp-config.php