PHP memory limit

php

In PHP 5.0.4, if you don't configure -enable-memory-limit, the memory_limit directive is ignored. (It's set to 8M in the recommended php.ini file, but the documentation says it's ignored.) So in that case, is there a per-script memory limit at all, or is it only limited by the system?

I ask because I'm upgrading to PHP 5.2.8, and it does allow memory limiting by default. So now I actually have to set the value to something appropriate. The recommended php.ini file now has it set to 128M, but I don't know if that's more or less than what 5.0.4 did by default!

I'm upgrading production systems, so I'd like to avoid any major change in behavior. The documentation (search for "memory_limit") is very confusing on this point. It says "default", but I don't know if that means the default value set in the config file, or the default value that it uses when memory limiting is disabled.

Best Solution

The memory limiter in PHP is optional; if you disable it at compile time there's no limit at all.

In 5.0.4 it's disabled unless you explicitly asked for it at compile time, the reason being that the memory limiter was useless until 5.2 and didn't count a lot of things it should have done, including things like the mysql functions. It's turned on from 5.2.1 now that they learned to count.

If in doubt, disable it or make sure you update the config file to use the new default. Leaving it at 8MB and upgrading to 5.2.8 will almost definitely cause problems.