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

WordPress Error Fix(?): Increase PHP Memory for cache.php

This trick isn’t guaranteed to prevent all WordPress-generated PHP memory errors, but it certainly seems to help reduce their overall occurrence. For some reason, after my host upgraded their servers to Apache 1.3.41, I began logging an extremely high number of fatal PHPmemory exhausted” errors resulting from the WordPress cache.php script. Here is an example of the countless errors that are generated:

[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
.
.
.
[ + lots more ]
.
.
.
[17-Feb-2008 19:36:19] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 6253069 bytes) in /home/.../press/wp-includes/cache.php on line 330
[17-Feb-2008 19:37:10] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 6379449 bytes) in /home/.../press/wp-includes/cache.php on line 330
[17-Feb-2008 19:37:56] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 6263789 bytes) in /home/.../press/wp-includes/cache.php on line 330

After researching online and learning that I am not alone with this issue, I deployed a threefold defense strategy to eliminate future memory conflicts related to the now-infamous cache.php pandemic. First, open the file wp-includes/cache.php and place the following code immediately after the opening <?php tag:

ini_set('memory_limit','32M'); // set memory to prevent fatal errors

After that, create an htaccess file for the wp-includes directory and insert the following directive:

# set memory limit for cache.php
php_value memory_limit 32M

Finally, create a local php.ini file in the same directory (wp-includes) and insert this:

;; set memory limit for cache.php
memory_limit = 32M

And that’s it. Save, upload, test and check for additional errors. If necessary, you may wish to try alternate values for the memory limit. I am not positive, but I think that valid values include 8, 12, 16, 32, 64, 128, ...etc., but the upper limit will vary depending on your server settings. Like I said, it doesn’t always work, but it definitely seems to help reduce the overall volume of memory-related errors in certain environments.

Download

To help speed up the process, I have zipped a complete set of the three required files in their respective formats. Simply unzip, upload and done:

PHP Memory Control Pack Version 1.0 (597B zip)

Note: If you happen to have absolutely any idea(s) as to why this problem continues to occur, there is a growing number of WordPress users (myself included) that are desperate for the answer. As mentioned in the article, increasing/limiting PHP memory (via any method) does not always work. Unfortunately, many users continue to log hundreds of these errors every day. Any clues and/or alternate fixes are more than welcome!</note>

Jeff Starr
About the Author
Jeff Starr = Web Developer. Book Author. Secretly Important.
Digging Into WordPress: Take your WordPress skills to the next level.

9 responses to “WordPress Error Fix(?): Increase PHP Memory for cache.php”

  1. Thanks Jeff.
    Tagged !

  2. Jeff Starr
    Perishable 2008/02/18 9:20 am

    My pleasure! :)
    I hope someone finds a more permanent solution for it!

  3. puredoxyk 2008/03/19 5:46 am

    WOW, lovely — fast and easy and worked like a charm. Thanks much!!

  4. Jeff Starr

    You’re welcome — glad to be of service! :)

  5. This solved my problem!
    Appreciate your help!

    Thanks a lot!

  6. Jeff Starr
    Perishable 2008/04/06 8:49 am

    Excellent — great to hear to got it working! Thanks for the feedback!

  7. Worked Great! Thanks for the info!

  8. Jeff Starr
    Perishable 2008/04/20 8:17 am

    My pleasure — thanks for the feedback! :)

  9. Thank you so much!

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
iCloud is like the Terminator. It will never stop trying to get your data. An endless fight on each Apple device to keep iCloud disabled and empty.
Take a screenshot with Firefox (no extension required). Open Developer Tools Settings and enable the “Take a screenshot” button. Then click the button :)
Take a screenshot with Chrome (no extension required). Open DevTools, type Cmd + Shift + P, then type screenshot.
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.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.