New Bookstore! Save 20% on books with discount code: LAUNCH
Web Dev + WordPress + Security

Improve Site Performance by Increasing PHP Memory for WordPress

During the recent ASO server debacle, I raced frantically to restore functionality to Perishable Press. Along the way, one of the many tricks that I tried while trying to fix the dreaded “white screen of death” syndrome involved increasing the amount of PHP memory available to WordPress. This fix worked for me, but may not prove effective on every installation of WordPress. If you are unsure as to whether or not you need to increase your PHP memory, consult with your host concerning current available memory1 and overall compatibility with a localized increase. Note that if your blog is running fine, there is probably no need to employ this solution. I recommend this change only if you are experiencing PHP-related and/or PHP memory issues associated with any of the following:

  • Inability to open various WP Admin screens (e.g., Themes, Plugins)
  • Inability to leave comments or no returned page upon leaving a comment
  • Inability to search or send feedback via various comment forms
  • Broken plugins (e.g., XML Sitemap Generator, DD Sitemap Generator)
  • Experiencing various timeouts (e.g., file uploads, page loads)
  • Unexpected downloading of PHP files via Firefox
  • Explicit PHP memory errors

If you are experiencing any one (or more) of these various issues, increasing your blog’s PHP memory limit may be the solution.

Increase PHP Memory for WordPress

First and foremost, backup your files — especially, backup your blog’s wp-config.php file (typically located in the WordPress root directory). Once you have done that, open your wp-config.php file and place the following code directly after the opening PHP element as follows:

<?php 
@ini_set("memory_limit","16M");
.
.
.

Save and upload the file and check your site. If you are still experiencing problems with any of the above-listed issues, try emptying your WordPress cache (if applicable) and/or deleting and re-creating your WordPress object cache. Then, if things are still acting bonkers, you may try incrementally increasing the amount of available PHP memory. Depending on your current settings, you may increase memory to the following values:

@ini_set("memory_limit","12M");
@ini_set("memory_limit","16M");
@ini_set("memory_limit","32M");
@ini_set("memory_limit","64M");

Targeting specific files

By maintaining and investigating a PHP error log, it may be possible to determine exactly the file or script that is causing the memory errors. For example, ever since my hosting company upgraded their servers to Apache 1.3.41, the WordPress cache.php file has been generating a large number of PHP memory errors similar to the following:

[17-Feb-2008 19:26:38] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 6233929 bytes) in /home/.../press/wp-includes/cache.php on line 330
[17-Feb-2008 19:30:57] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 6327989 bytes) in /home/.../press/wp-includes/cache.php on line 330
[17-Feb-2008 19:33:35] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 6253909 bytes) in /home/.../press/wp-includes/cache.php on line 330

Thus, given this information, I decided to target the source of the issue, by increasing memory exclusively for cache.php. Although results may vary, in general, directly targeting the source of the conflict may work better than globally applied specifications. I will be writing more on the memory errors associated with the WordPress cache.php file in the near future.

Wrap up..

Remember that your specific hosting environment will affect the degree to which this technique proves effective. Also note that it is possible to raise your memory via php.ini or even htaccess. Further, the memory-increasing techniques described in this article utilize common PHP directives and may be applied to virtually any PHP-driven script or platform. As always, share your insights with our growing community!

Footnotes

  • 1 To check your available PHP memory, upload a phpinfo.php file containing <?php phpinfo(); ?> to your server and call it in a browser. Scroll down about one screen and locate the line that says, “memory_limit” — the value given represents your server’s current PHP memory limit.

Jeff Starr
About the Author
Jeff Starr = Creative thinker. Passionate about free and open Web.
Blackhole Pro: Trap bad bots in a virtual black hole.

2 responses to “Improve Site Performance by Increasing PHP Memory for WordPress”

  1. Freshers Jobs 2008/10/25 11:54 am

    Good Article … I am using a PHP Query to calucate the Number of Queries made to the database when a page displayed. I am getting around 28 queries on the homepage.

  2. Chimmequame 2009/05/20 12:24 pm

    Great post:D Will definitely come back again soon!!

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
USP Pro: Unlimited front-end forms for user-submitted posts and more.
Thoughts
After 10 years working on my 2010 iMac, my upgrade finally arrived. Shiny new iMac shipped from Ireland :)
Too much caffeine weirds me out. But I love the taste of coffee. So once in a while I enjoy a small cup of decaf. Hits the spot.
Chris Coyier is a truly awesome person. One of the finest people I've ever worked with. Just #gottasayit
Excel won't open CSV file because SYLK format? Open it with text editor and add an apostrophe ' at the beginning of the file, save changes, done.
Displaying too many social media buttons and links all over the place imho makes you look desperate and frankly kinda sad.
Interesting and insightful domain security scanner. Could spend hours playing.
Seeing massive increases in spam and malicious attacks across the board. Nothing out of the ordinary, just a LOT more of it.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.