Back to Top

WordPress’s Memory Usage, should it be one of your concerns?

Previous Post:

WordPress’s Memory Usage, should it be one of your concerns?

As a WordPress end-users, you might never care about the term “Memory Usage” until you encounter a fatal error that prevents your site from working:

Fatal error: Allowed memory size of … bytes exhausted (tried to allocate … bytes) in somefile.php: …

Don’t panic just yet, you’re not alone:, other WordPress users are having the exact same problem.

The term Memory Usage (in WordPress’s case) is used to refer to how much memory your plugins, themes, and WordPress core files consume when they get parsed and then processed server-side.

WordPress’s core files (3.0’s Twenty Ten theme installed) consumes about 13MB of memory (on some hosts with added modules or features, this number can be even higher. For example, it is 16 instead of 13 on one of my websites). Of course, you would have no problem installing WordPress on any host, because 13MB is easily satisfied (most hosts offers a 64MB or 32MB limit by default).

Exceeding the limit

The problem is, you are not happy with the default WordPress installation with limited functionality, you need some plugins and, obviously, a theme.

A web developer told me that he couldn’t live without at least 30 plugins, so let’s take a rough assumption of an average number of installed plugins of 20 (plus 1 theme, a special kind of plugin).

A plugin can be very small (for example, Hello Dolly – a dummy plugin created by Matt Mullenweg – only adds 6KB to memory usage), or can be very large (for example, GD Star Rating 1.9.x – a popular rating plugin – adds more than 4MB to memory usage).

Although the calculation should base on how a plugin or theme is loaded but let’s again take a rough assumption of 1MB memory usage used per plugin, we shall have the fully-loaded WordPress installation that consumes more than 33MB.

If your host is configured to use the 32MB memory limit, you will surely be greeted with the fatal error message we are discussing about.

When you got stuck with such error, you will certainly pay Mr. Google a visit and you will find some straightforward solutions regarding changing such limit. If you come to this page thanks to Mr. Google, I will gladly quote those solutions so you don’t have to go find elsewhere.

So, you can try:

  • Adding memory_limit = 64M to your server’s php.ini if you have access to it
  • Adding ini_set('memory_limit', '64M'); to your wp-config.php
  • Adding php_value memory_limit 32M to your .htaccess file

(Note that, however, if you’re on a shared hosting system, most of the time you won’t be able to change the limit using the above methods. You will have to ask your hosting provider to change it for you.)

General speaking, the above solutions work, but they are not recommended, why? Because the more you raise this limit, the sooner you fall into a common pitfall: too much work for the server. A higher memory limit is a poor substitute for good coding and can be very problematic, especially for high traffic websites.

In case you guys don’t know, each time a visitor clicks on something on your website, he or she is telling your server to work hard and output some kinds of result. A server is nothing mysterious, it is a computer, with hardware, software, RAM, etc. and they consume power, a lot of it.

One of the things you probably notice when registering for a new host is the CPU usage limit (consumed by PHP scripts parsing and possibly other processes). Such limit is set differently for each hosting company, for example, HostGator allows a 25% CPU Usage limit – More visits, more clicks, and more script parsing will demand more CPU usage. Your website might be inaccessible, or worse, got disabled by the hosting company for “consuming more system resources than allowed”.

Now that I am writing this not to scare anyone to death, it is a common mistake in many websites nowadays, too much contents requiring too much work from the server. Some websites use about 61MB memory and make about 126 queries to the database. 61MB is way too high for every page load, don’t you think? I myself never use more than 30MB memory and 40 queries for a single page (except for some specific situations or specific pages, and FYI, only uses an average of 16MB memory and 25 queries per page), 126 is a figure I simply can not imagine.

More solutions

There are some obvious solutions that you can apply without waiting for plugin developers to do their job:

  • Use fewer plugins and well-coded themes. Don’t get me wrong, this is the best solution and require professional work. Some useful tips and articles about avoiding using plugins, if you are interested: topic/plugin-alternatives/
  • Use cache plugins. All the high traffic websites use them. I will recommend WP Super Cache or Hyper Cache if you ask me.

There’s a somewhat hackish solution that I called Selective Plugin Loading. I have written a follow-up post regarding such solution, and you can read it here: Selective Plugin Loading.

The ideal scenario is, of course, the plugin authors change the way they load their plugins, by loading only when needed or, even better, allowing users to choose when to load. This is such a big favour to ask from all plugin developers and I do believe it would need some kinds of APIs or at least an official guide and announcement from the WordPress team, otherwise plugin developers will unlikely take any action.

Anyone who has opinions about this problem please comment below. If you guys would like to ask about the selective plugin loading solution, comment on that article would be ideal. That’s all I have to say, thank you for your time, be safe and stay away from memory-eating plugins and themes 😉

Further Reading

Take Social Sharing to
the Next Level with Monarch!

Take Social Sharing to the Next Level with Monarch!
Print Article Trackback Trackback to this Article   Subscribe to Comments RSS Subscribe to Comments RSS

11 Opinions for WordPress’s Memory Usage, should it be one of your concerns? (6 Trackbacks)

  1. User's Gravatar
    jerry January 23, 2012 at 10:34 pm – Permalink

    Over memory usage happens to me quite a lot.
    Thanks for explaining why it happens, and what to do about it.

  2. User's Gravatar
    Benedita June 12, 2012 at 10:40 pm – Permalink

    thanks for such a great post and the review, i am totally impressed!%3

  3. User's Gravatar
    Geekyard October 16, 2013 at 1:40 pm – Permalink

    My website frequently overloaded, although traffic is not big, really difficult when I use wordpress.

  4. User's Gravatar
    Shirley, Bar Native March 19, 2014 at 9:24 am – Permalink

    Yeh, we just launched Bar Native and are trying to make it work as efficiently as possible. Fortunately, since it is our site, we can weight features against site performance. For other sites, I generally have to weigh what the client wants over site performance, and inevitably, we end up with a slow site or super expensive hosting.

  5. User's Gravatar
    Hamed June 20, 2017 at 2:42 pm – Permalink

    good place to start to know your memory limit settings, in Server Status

    if WP limit doesn’t match PHP limit so its one of the biggest problems, just match them

  1. Selective Plugin Loading «

    [...] core file. Before continuing on with this approach I highly suggest that you read an article about Memory Usage to get a better idea why we have to do this. Print Article Trackback to this Article [...]

  2. Add’s Polls to Your Blog «

    [...] is rather heavier than needed (and you might find yourself troubled by the memory usage limit1 before you know [...]

  3. Ten Useful WordPress Constants You Might Love - Better WordPress

    [...] (New to memory limit? Check out this article on WordPress’s memory usage.) [...]

  4. wordpress plugin review and discussion. |

    [...] Also, you can try the tips mentioned in this post of mine. [...]

  5. Better WordPress Google XML Sitemaps (with sitemapindex and Multi-site support) | WordPress Designer

    [...] Also, you can try the tips mentioned in this post of mine. [...]

  6. Speed Up WordPress: A Developer's POV - Better WordPress

    [...] simple: bad hosts will fail even when you use / develop highly optimized plugins or themes. Try installing WordPress on a shared host with low PHP memory limit and you will understand what I [...]

Speak Up Your Mind!

An asterisk (*) indicates a required field and must be filled.

  • Web page and e-mail addresses turn into links automatically.
  • Wrap codes in: <code lang=""></code> or <pre lang="" extra="">
  • Lines and paragraphs break automatically.

Next Post: