Notice: Trying to get property of non-object in /var/racent/racent/module/Post/src/Post/Controller/HostucanController.php on line 587

Notice: Trying to get property of non-object in /var/racent/racent/module/Post/src/Post/Controller/HostucanController.php on line 587
How to Increase PHP Memory Limit | HostUCan Webmaster Tutorials

How to Increase PHP Memory Limit

2015-01-24 09:26 Posted by: Davis Paul in PHP, Tutorials Go to Comment

When you saw an error like “Fatal Error: Allowed memory size of xxxxxx bytes exhausted” in either browser or server logs, it means PHP had hit its memory limit. Mostly, this is due to the insufficient memory allocated for PHP script. And in below, we will talk about how to increase the momory limit of PHP.

Check PHP memory_limit

To know the value of PHP memory_limit, you can check the configuration in PHP.ini. However, sometimes you might not know where php.ini is located. So, the simplest way is to use execute PHP function phpinfo(), which will display all the php related server configuration.

To do so, you need to create a PHP file (we can name it as view-php-info.php), and put following code in it:

<?php phpinfo(); ?>

Upload the file to your web server, and access the file in your browser, you'll see a table which lists out all the config about current php environment. Search for "memory_limit", you'll see:


In above case, we set the PHP memory_limit to 128M in our testing environment.

By the way, you can use this method to verify the change of PHP memory limit.

How much memory do I need?

It depends, for wordpress core, 32MB is good enough. For drupal6 core, the min memory limit is 16MB, 32MB is recommended. But if you install many plugins, especially the plugins deal with image, you probably need a memory with 64MB or more.

Increase PHP memory_limit

Way1: Modify php.ini

The most easy and common way is to change the configuration in php.ini

  1. Firstly you need find your php.ini . In the report generated by phpinfo() (you can use PHP script created in above), there is a parameter called "Loaded Configuration File" (see below), that's where your PHP.ini file is located. If you use Linux, you can simple run the command "php -i | grep Loaded Configuration File" to find it.For windows user, you can find it in your php install directory.
  2. Edit php.ini .Search "memory_limit" in your php.ini, and change the value of it. If no "memory_limit" found, add the following line at the end of php.ini
    memory_limit = 128M ; /* Change the 128M to your needs */

    Save file.

  3. Restart Apache. Use follow command to restart apache:
    httpd restart

For some restricted environment, such as shared hosting user, your web host might not allow you to php.ini directly, then you could consider the follow ways.

Way2: .htaccess

Notice: This method will only work if PHP is running as an Apache module.

Find the ".htaccess" in your root directory of the specified domain, if there isn't, create one. Put the following line in it.

php_value memory_limit 128M; /* Change the 128M to your needs */

Way3: Change Memory At Runtime

Right, PHP memory limit could be changed at runtime. Via this way, you have no need to change and configuration of your server environment.

For Wordpress Users

In your wp-config.php, find or add the following line:

define('WP_MEMORY_LIMIT', '64M');

WordPress will automatically check if PHP has been allocated less memory than the entered value before utilizing this function. For example, if PHP has been allocated 64MB, there is no need to set this value to 64M as WordPress will automatically use all 64MB if need.

Notice: By default, WordPress will attempt to increase memory allocated to PHP to 32MB (code is at beginning of wp-settings.php), so the setting in wp-config.php should reflect something higher than 32MB.

For Drupal Users

For drupal, you can edit sites/default/settings.php. Locate the PHP settings section and add the following line at the end of that section:

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

This method will affect only the site using this file.

For other frameworks

Similarly to Drupal, in your code, you can add the following line in your php code. That will take effect at runtime.

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

Increase Failed

There are many reasons that can lead to increase failed. If you are a shared hosting user, the most possible reason is that your hosting vendor does not allow for increasing the PHP memory limit, in this case, contact your host to increase the PHP memory limit. Some web sites might reject to increase PHP memory limit since this means your site require more server resource than normal. If this happens, then you can consider to change your php hosting to those who allows for large PHP memory limit.

Tagged with:

Related Articles

Importance Of Cloud Computing For Businesses
Gone are the days when an IT department of an industry relies entirely upon the personal setup of software, hardware, business SAPs, etc. Today, the time has evolved to a newer face of the data processing machines called ‘Cloud Computing’.
What are the Drawbacks of Using Cloud Computing?
Cloud computing seems to have become quite popular and hundreds of companies including some of the top ones seem to be quickly shifting to cloud storage. While there are many advantages that cloud computing has the process isn’t without its disadvantages.
What Does Latest OpenStack Ocata Bring for Us?
OpenStack now is still an on-going project, whose components are in different stability and mature phases. It also means enterprises are confronting OpenStack deployment challenges, especially in the terms of scalability and network. The new version of OpenStack brings something new to handle the issues found before.
Most Common Website Security Mistakes
There are several factors that the website developers need to take care of while designing and developing a dynamic website.
LiquidWeb Brings Innovation Back to Managed WordPress Hosting
LiquidWeb is not done with its managed WordPress hosting yet! Now it comes back to customers with new tools to help them visualize their site changes. A new visual comparison tool as well as automatic SSL is now included in LiquidWeb managed WordPress hosting plans, addressing customers’ demands and pain points very well.
Be the first to comment!
About the author

Notice: Trying to get property of non-object in /var/racent/racent/module/Post/view/ctrl/author-introduction.phtml on line 5

Notice: Trying to get property of non-object in /var/racent/racent/module/Post/view/ctrl/author-introduction.phtml on line 7

Notice: Trying to get property of non-object in /var/racent/racent/module/Post/view/ctrl/author-introduction.phtml on line 16

Notice: Trying to get property of non-object in /var/racent/racent/module/Post/view/ctrl/author-introduction.phtml on line 16
Views: 222443
Articles: 92

Notice: Trying to get property of non-object in /var/racent/racent/module/Post/view/ctrl/author-introduction.phtml on line 19

Author's Hot Articles


Hot Posts

Service Recommendation

Cloud Hosting
Cloud hosting is the fastest growing hosting solutions in the industry. »
Cloud Storage
Best Cloud Storage are named based on customer and expert reviews. »
The most popular SSL certificate providers in the industry are here. »
China Web Hosting
Find out a comprehensive evaluation to the host service provider in China. »
Chat Advertising cooperation TOP