| 1 comments ]

tips on error 'Allowed memory size of xxx bytes exhausted'

While working on php, the is chance to get following error "Allowed memory size of xxx bytes exhausted". The reason behind this error is that, Setting the memory limit using the memory limit on the server was exhausted. This is often happens with page with large data, or too many loops, condition checking, or large file uploading etc.

By default the memory limit is 8M we can change this value, by editing the php.ini file. if you are in a dedicated server, we can edit its value on php.ini file and then restart the appache server. But in shared hosting, this issue is very common. usually have no access to php.ini file.

if you have no access to php.ini, we can set these values through coding in php, for that we need to use the following function;

string ini_set(string $apache_variable,string $newvalue);

example :

ini_set('memory_limit','16M');

In some servers we could not do this, in that case we have have an alternative to do this , we just want to use the .htaccess file. we can describe the memory_limit on this file, if there is a .htaccess file, just edit the file and add the desired code.Other wise, create a new one by saving a text file with the name .htaccess, and put it into your working directory.

command

php_value memory_limit [new memory limit]

example

php_value memory_limit 32M

enjoy PHPing.....

1 comments

jj said... @ Thursday, May 14, 2009 at 7:31:00 AM GMT+1

we can also give -1 to memory limit in the case we don't want any memory lomit on our script.

ini_set('memory_limit','-1');

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.