Monday, May 23, 2011


We know that default memory limit in PHP is 16MB. Sometimes we need more than 32 MB or 64 MB. As well as default file upload limit is 2 MB that is fairly low – and especially when site works on Photos. As script execution time, default time is 30 sec but some times, tasks require more execution time to complete their jobs.  Here are few techniques for enhance PHP memory limit, file upload limit and execution time. These techniques depend on your system configuration.

1. Set Memory Limit

1.1. php.ini configuration This is the suggested approach if you have access to the server's php.ini. This will not be possible in most shared hosting situations, though your host may be able to adjust it for you. Note that this change will affect all websites and PHP scripts on the server. - Locate the php.ini file used by your web server. You can use the phpinfo() PHP function to find it. - Edit the memory_limit parameter in the php.ini file (usually in a section called Resource Limits) memory_limit = 32M; Maximum amount of memory a script may consume (32MB) If there is no section already for this, place the above line at the end of the file. - Restart Apache. Note: If you are using XAMPP/WAMP, there may be two PHP.ini files (one under the PHP directory and the other under Apache/bin). To change your memory limit, edit the file in the XAMPP/Apache/bin directory. The next two solutions are more restricted in scope and, in some cases, may be more appropriate choices than affecting all sites.

1.2..htaccess configuration This is useful when you do not have access to php.ini file. Edit (Create) the.htaccess file in the site root (public) directory and add the following line: php_value memory_limit 32M This method will only work if PHP is running as an Apache module.

1.3. Configuration in PHP scripts Add the following line where you need to give PHP more memory: ini_set('memory_limit', '32M');

1.4. Memory limits on Shared Hostings. In some shared hosting environments, access to the PHP memory limit setting is restricted. If you cannot make the change yourself, please ask your hosting provider to adjust it for you, or look for a new host that allows more flexibility.

In part - 2, we will discuss about File upload limit. 

development, apps development india