Spring Sale! Save 30% on all books w/ code: PLANET24
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.

About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
Banhammer: Protect your WordPress site against threats.

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 »
GA Pro: Add Google Analytics to WordPress like a pro.
Thoughts
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
First snow of the year :)
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.