The memory_limit
is the maximum amount of memory a PHP script is allowed to use. Basically, this is a security configuration option, to ensure you don't have a PHP script that does mad and consumes all the memory of the server -- or worse, that you don't have several PHP script that eat more memory than the server has.
This configuration directive can be set in the php.ini
file ; it's the file that sets the configuration of PHP.
To find out where the php.ini
file is on your server, you can use the phpinfo()
function : somewhere near the top of the output, there should be a "Loaded Configuration File
" option.
Which value should be used for memory_limit is an interesting question... In the past, when we were only writting small script, 8MB
was generally enough.
Now, with Frameworks, bigger applications structured in layers, ORM, and all that, 8MB
is generally not enough (as you obviously noticed) -- I generally set memory_limit
to 32M
on my production servers, which is almost always enough for my applications, without being too much.
So, in my php.ini
file, I have :
memory_limit = 32M
Note : it would be tempting to put a very high value for memory_limit
, to just get rid of the problem... But remember that memory_limit
is here as a security : you should make sure your server has enough memory to answer several requests at the same time !