Posted on 14th Mar, 2008 14th Mar 08
Posted by fran fran

PHP Memory and Wordpress

Sometimes when Wordpress runs out of available RAM on its housing server, it can yield some pretty strange results, including blank pages, timeouts, and unexplained errors. Wordpress isn’t terribly verbose about memory related errors when they are encountered, and as such – one can spend a lot of time looking for errors in your PHP code, where none truly exist.

If Wordpress runs into its server’s memory limit whilst rendering a page, more often than not, it will simply shut down – leaving no error message or indication of what had caused the problem, simply an ominous white screen, and a couple of lines of source code.

There are a multitude of signs that your installation of Wordpress hasn’t got enough memory to function correctly:

  • Partially or Fully Blank Screens.
  • Admin Sections not rendering fully (reading-options.php seems to be a widespread indicator, failing to render below the first drop down box) .
  • Plugin Management not rendering completely.
  • Sections of the site which rely on the wp_list_pages tag not rendering fully or at all.

If your pages are rendering partially, its useful to look at the point in the source code at which Wordpress ceased rendering the page, as this can give us an indication of the process which caused the installation to tip over the limit.

In my experience, if a clent’s Wordpress installation needs to serve a lot of pages (when using Wordpress in a CMS role), the wp_list_pages tag can act as the tipping point on servers with low system memory. With enough pages, this tag can eat through aroud 15MB+ of an allowance. Couple this with a multitude of other PHP processes, and you’ll blast your way through a basic shared hosting package’s RAM very quickly.

We can quickly check what our memory limit is for operation of our scripts by creating a file with the content:

<?php phpinfo(); ?>

Name this file phpinfo.php, and upload it to your server. Visit the newly created page, and search for the term: ‘memory_limit’. This will tell you how much space your site has to do PHP calculations – if it’s in the 20MB region, you’re very likely to encounter problems with sites including larger volumes of content.

Without any explicit indication of what is causing an error on your installation of Wordpress, one can feel a bit lost – especially when with some shared hosting packages *cough*1and1*cough*, you aren’t given access to your server error logs.

As a lot of these hosts aren’t forthcoming in granting a larger slice of shared memory without a costly upgrade, it’s important to be fairly certain that memory limit is what is causing the problem, before taking the plunge and urging a client to upgrade their package. There’s a few things we can do that can implicate low memory as a core problem:

Test to see whether there is any improvement after:

  • Taking Plugins Offline.
  • Switching large sections of the site onto ‘Draft’ mode (i.e pages with large quantities of sub-pages).

It is worth pointing out that whilst low PHP memory can be the root of rendering problems, it can also be the case that a badly written plugin or modification to Wordpress’ core code may munch its way through vast swathes of system RAM. It’s important to make certain that any code is well formed and written, before placing blame on the package’s low memory.

When reducing Wordpress’ memory footprint, there’s a few tricks that can help us to make progress. Converting tags such as bloginfo(’template_directory’) to their hard coded counterparts can help reduce system load, and Disabling plugins which aren’t core to the operation of the site.

If you’re lucky enough to be able to up your memory limit without an account upgrade, Perishablepress has a great guide on how to go about the process, and some good advice surrounding the issue in general.

Tags: , ,

9 Responses to “PHP Memory and Wordpress”

  1. Posted by David David Says: Comment by David

    Wordpress is great software for bloggers who wish to setup a new site without much hassle – But I am surprised at how much of the code still needs to be optimized. For example, on a vanilla install with no plugins and only 1 post it takes 8-10Mb just to show the index page. What if your host has 5 of these on it?

    5 Blogs each with 5 people online at the same time = 250MB (with no plugins)

  2. Posted by Ivanski Ivanski Says: Comment by Ivanski

    thanx folks, I like you

  3. Posted by Upgrading Wordpress to 2.7.1 « In Search of a Good Title Upgrading Wordpress to 2.7.1 « In Search of a Good Title Says: Comment by Upgrading Wordpress to 2.7.1 « In Search of a Good Title

    [...] It appears that the real problem is php memory. This post seems to echo my problem: php-memory-and-wordpress. [...]

  4. Posted by Wordpress, PHP Memory, and 1and1.com « In Search of a Good Title Wordpress, PHP Memory, and 1and1.com « In Search of a Good Title Says: Comment by Wordpress, PHP Memory, and 1and1.com « In Search of a Good Title

    [...] updated as I posted about here. However, it I think the problem is closer to the one described at: php-memory-and-wordpress. That is PHP is running out of memory. I am currently hosting the site at 1and1 on a developer [...]

  5. Posted by Nimwit Nimwit Says: Comment by Nimwit

    Thanks for this post. Do you know of any plugins that actually monitor Wordpress live php memory usage?

    N.

  6. Posted by Nimwit Nimwit Says: Comment by Nimwit

    Anyone reading this post might also like to view this post which relates to it, which I have also just read.

    http://php-fatal-errors.iamuk.co.uk/

    N.

  7. Posted by bimo bimo Says: Comment by bimo

    Great articles & Nice a site

  8. Posted by smannadywosse smannadywosse Says: Comment by smannadywosse

    http://www.bkgm.com/rules/rulfig1.gif

    Sie Brettspiel online. Lernen Sie Brettspielregeln und tragen Sie Brettspielturniere online zu spielen und ein gegen Millionen von deutschen Verbrauchern online zu gewinnen. Die hintere gammon Website und Software sind 100% frei.

    GammonEmpire ist die gro”?te Online-Brettspielgaminggemeinschaft. Spielen Sie Online-Brettspiel, tragen Sie in zuru”ck gammon Turniere, Sieggeld, trifft Leute, ein lernen Sie Brettspielregeln, und genie?en Sie eine gro?e Erfahrung online. Wir haben Verbraucher von allen um die Welt. Wir haben u”ber 3 Millionen Deutsch, das eingetragene Verbraucher in unserer Gemeinschaft mit einem Durchschnitt von 90k Deutsch Sprechen Mitgliedern spricht, hat sich angemeldet an irgendeine gegebene Zeit.

    Diese Brettspiele platzieren Angebot ein Safe und sichert Online-Umwelt, wo neue Spieler lernen ko”nnen, wie zu spielen Brettspiel mit den leichten Regeln und die Strategien auf dieser Stelle versorgt haben. Ob Sie ein Online-Brettspiel Spiel fu”r Anfa”nger oder ho”here Spieler suchen, ko”nnen Sie freie Brettspielsoftware und Spiel gegen andere Spieler an Ihrer Ho”he auf dem Internet laden. Auf diese Weise ko”nnen Sie Erfahrung sammeln und ko”nnen Ihr Spiel in Vorbereitung auf wirkliche Geldspiele oder geplante Online-Brettspielturniere verbessern. Zusa”tzlich, Sie ko”nnen lernen wo zu spielen Online-Brettspiel, sowie Ihre Fa”higkeiten auf dem Ausschuss durch Verwenden von des nu”tzlichen Brettspiels Anweisungen und Artikel verbessert. Mittlerweile ko”nnen Sie unseren 30% Bonus genie?en, auf der Sie zuerst deponieren, sowie ein $5 willkommener Bonus.
    http://www.backgammon-directory.info/design/BD_01.jpg

  9. Posted by Matt Matt Says: Comment by Matt

    Good, clear article, and a very nice looking site.

Leave a Reply