View Full Version : memory_limit not being recognized

05-12-2009, 12:16 PM
Hi all,

On my development machine, I am running PHP 5.2 under Apache 2 on Debian Etch.

I have auto-updates turned on in Debian (so that apt-get will prompt me when a newer version of anything turns up).

Anyway, I had been using PHP 5.0 and the other day I upgraded via the Debian server to 5.2.

All well and good.

Now, ages ago (under PHP 5.0), I ran into a memory limit error when using PHP CLI, so I changed the memory limit from 16 to 32 MB, and all was good. (Note that the Apache2 limit can remain at 16).

About an hour ago, lo and behold, I ran into the same error again! I checked the /etc/php5/cli/php.ini file - nope it's still the same as before: "memory_limit = 32M".

So I ran "php -i" from the command line and as part of it's output, I get the following:

Configuration File (php.ini) Path => /etc/php5/cli (yep, that's what I would expect).

But then:
memory_limit => 16M => 16M

What the hell ?! :confused::confused::confused: It tells me it is looking at /etc/php5/cli to get it's configuration, and in that file I have set the memory limit to 32MB, but it still tells me its 16MB?

I double-checked against the output from my code: Fatal error: Allowed memory size of 16777216 bytes exhausted ... and yep, 16777216/(1024*1024) = 16MB.

Any suggestions will be gratefully received!


EDIT: I have checked the PHP documentation and it says that the memory_limit directive has no effect in versions earlier than 5.2.1 unless the -enable-memory-limit option is included at compile time. I am using version 5.2.0-8 ... so I can only assume that that option was not included by the Debian people at compile time ... but obviously it was included when they built version 5.0. So why the blue buggery blazes would they switch the damn thing off in the newer version ???!!!!!

EDIT 2: I have found the following work-around: php -d memory_limit=32M -f myscript.php. That would suggest that -enable-memory-limit was included at build time, but it still doesn't explain why PHP is not picking up my changes in php.ini! So I have to manually set the memory limit each time I call the script. Not onerous, but a pain in the arse and I would like to get to the bottom of this. All ideas welcome :)

05-12-2009, 03:49 PM
have you tried running phpinfo() to see what that says? It should tell you the location of the ini file its using and will list local and master values for all the settings.

05-12-2009, 04:10 PM
Hi, yep, I have tried that! It says 16Mb and it points to the file that I have edited to set the limit to 32Mb :confused: This has always worked for me before, and it's such a simple thing that I am completely stumped! phpinfo() is equivalent to "php -i" in cli mode.

05-12-2009, 04:17 PM
This may sound stupid but you are restarting apache aren't you?

05-12-2009, 04:38 PM
Yes, I have tried that. Anyway, the problem is with cli and not apache2, so it shouldn't matter.

05-12-2009, 04:42 PM
Yes, I have tried that. Anyway, the problem is with cli and not apache2, so it shouldn't matter.

Ah ok i just know when i make changes to my php.ini i have to restart apache for them to take effect (or at least that's what i seem to have to do). was just checking.

05-12-2009, 04:44 PM
Yep, that will affect scripts run on the server - but if you're running it from the command line, it uses a different .ini file which is independent of the server.