Improve the Memory of your WordPress Site

computer memoryWordPress loves memory! Lack of sufficient available memory can lead to slow response, and in the worst case can cause operations to fail. So how much memory is enough?

Prior to 3.0, 32 to 64 MB of memory was sufficient for the average WordPress site. With more admin tools and plugins, 64 MB is now considered a minimum and 128-256 MB is recommended. (WordPress versions prior to 3.2 do not allow exceeding 256MB; this limit was removed in 3.2.) See Mysteries about the WordPress Memory Limit for more details.

If your site loads quickly, searches are snappy, and edits or updates are processed promptly, then you probably don’t need to look into this further. But if you find your site grinding along on some pages or tasks, then it’s a good idea to check your memory limit.

How do I find out how much memory WordPress is using?

Create a text file with one line of text in it:

<?php phpinfo(); ?>

Save this file with the name phpinfo.php or some other name you will remember. (Make sure it has the .php extension.) Then upload the file to a folder on your website, and use a browser to view the file. For example, if you place the file in the wp-content folder, you can view the file in the browser as http://mysite.com/wp-content/phpinfo.php.

When you view the page, you should see a long stream of information about the PHP environment on your server. Search or scroll down to the line that begins with “memory_limit.” You will see your current memory limit in the middle column and the system default limit in the last column.

If you have named your file something easy to guess, then make sure you remove if from your server after running it. If you want to keep it online, then change its name to something hard to guess and put it in a subfolder under your theme file or somewhere else that it won’t be seen.

How do I set a higher WordPress memory limit?

Your ability to change your WordPress memory limit depends on where your website is hosted. If you don’t own your own server, then your hosting provider will have a maximum memory limit that you will not be able to exceed.

If you’ve decided to give your WordPress site (or blog) more juice, first try one of these methods to increase the memory limit. We’ve used 128M (128 MB) in the examples. If you have a site that makes a lot of database references, uses large, complex scripts, or manipulates large images, you may want to set the memory limit to 256M.

  1. If you manage your own server and know to find the php.ini file on your system, you can edit the limit directly. Search for the “memory_limit” line and change it to read: memory_limit = 128M.
  2. If you have root access to the server and can locate the php.ini file, you can use the sedutility in Linux/Unix based systems to increase the memory limit.
    sed -i 's/memory_limit = .*/memory_limit = 64M/' /etc/php5/apache2/php.ini
  3. Add this where? ini_set('memory_limit', '16M');
  4. Add the following line to your wp-config.php file. This will increase the limit for all your WordPress files.
    define('WP_MEMORY_LIMIT', '128M');
  5. If you have pages or scripts on your site that are not part of WordPress, and want to increase the limit for them, too, add a line to your .htaccessfile setting a new limit:
    php_value memory_limit 128M
    
    

Now you need to visit your phpinfo.php file whether the change went into effect. You should see the new value in the middle column. If neither of the above methods work, then you will need to contact your web hosting provider technical support for assistance.

See more examples in 3 Ways to Increase PHP Memory Limit.

Photo credit: pschubert from morguefile.com

Leave a Reply

Your email address will not be published. Required fields are marked *