8

I am trying to set memory_limit to 512M, but it's locekd to 256M.

ini_set('memory_limit','512M');
ini_get('memory_limit');    //> Returns: 256M

I have full control on my server. (it's a dedicated)

Please note that everything under 512M works.

ini_set('memory_limit','16M');
ini_get('memory_limit');    //> Returns: 16M

Solution

I found out why. in php.ini I had memory_limit = 256M. Maybe this is considered as an upper limit

dynamic
  • 46,985
  • 55
  • 154
  • 231
  • possible dupe: http://stackoverflow.com/questions/5061917/ini-setmemory-limit-in-php-5-3-3-is-not-working-at-all – lamplightdev Mar 01 '12 at 15:47
  • 1
    Did you try raising it in php.ini as well? Or is this just a one-off thing where you want to grant only a specific script more memory? –  Mar 01 '12 at 15:56

6 Answers6

8

3 possibles I can think of / find:

Prior to PHP 5.2.1, in order to use this directive it had to be enabled at compile time by using --enable-memory-limit in the configure line.

OR

The issue detailed here: ini_set("memory_limit") in PHP 5.3.3 is not working at all

OR

ini_set is disabled

Community
  • 1
  • 1
Ingmar Boddington
  • 3,440
  • 19
  • 38
4

You can also try to change the memory_limit using either a php.ini or .htaccess file

php.ini

memory_limit = 512M;

.htaccess

php_value memory_limit 512M
Stephen Senkomago Musoke
  • 3,528
  • 2
  • 29
  • 27
3

A bit late in the day but editing the php.ini file didn't work for php 7.1 using Mac OS 10.11.6. I still kept on getting the 'PHP Fatal error: Allowed memory size of....' which from its value showed the memory setting was not updating after starting apache.

So instead of editing the file.

/usr/local/php5/lib/php.ini

I found changing the following file fixed this issue.

/usr/local/php5/php.d/99-liip-developer.ini

This file was actually replacing the values set in the initial php.ini file. Again making the following changes to the line...

memory_limit = 256M

to

memory_limit = 1024M

And restarting apache.

sudo /usr/sbin/apachectl restart
Paul
  • 129
  • 5
2

I noticed that on my Mac (OS X El Capitan) and the new PHP 7.0.0, I cannot change memory_limit via php.ini

But I can change it via /etc/apache2/httpd.conf by adding the line in the end:

php_value memory_limit 1024M

and restarting apache server:

sudo apachectl restart

And it is the correct php.ini , I can change other settings via it.

Oleksiy Muzalyev
  • 948
  • 11
  • 7
  • Good shout - however it should be noted that this will not change the *master* php value, and instead changes the *local* value for each site (as per the `.htaccess` or `ini_set` solutions) – Stumblor Dec 30 '16 at 12:53
0

You could check in your php.ini config file at the directive called "disable_functions". Check if ini_set is disabled.

Also if safe_mode is enabled such option may not be overriden.

musse1
  • 379
  • 4
  • 17
0

I found out why. in php.ini I had memory_limit = 256M. Maybe this is considered as an upper limit.

I rised it to my need.

dynamic
  • 46,985
  • 55
  • 154
  • 231