memory_limit sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server.
There are many ways by which you can set the memory limit.
1. Set memory_limit = 16M to your server’s php.ini file (recommended, if you have root access) [applies to the whole server]
2. Set ini_set(‘memory_limit’, ’16M’); to your site’s default settings file [in case of some CMS sites] [applies to the whole site]
3. Set php_value memory_limit 16M to your .htaccess file in the site’s folder [applies to the scripts under that folder].
To check the memory limit applicable in the server [or in a particular folder], create a filememtest.php in the desired location, with the below contents.
$step = 1;
$chunk = str_repeat('0123456789', 128*1024*$step++);
print 'Memory usage: '. round(memory_get_usage()/(1024*1024)) . 'M<br />';
Now access the file in your browser. The script executes till it reaches the limit.