Memory Hungry PHP Applications on Shared Hosting

If you run your WordPress on a shared hosting server like hostmonster.com / bluehost.com (which have excellent service by the way), and have several memory-hungry php applications or WordPress plugins installed, you must have run into an "Allowed memory size exhausted" fatal error a few times. For me it happened yesterday while uploading a mere 12MB of images (1MB per image) and trying to ask the NextGen Gallery plugin to discover them and generate thumbnails. WordPress ran out of memory after 32MB and died with the above exception.  Though one can't ask a lot from a 6$ per month hosting provider, and since 32MB ought to be enough for everyone (hehe), I decided to spend some valuable time in trying to find a workaround to the limitation, before deciding to dump the NextGen plugin. Here's what I found out:

  • The NextGen recommended method of setting the memory_limit in the plugin's code via php_ini function call does not work.
  • Trying to increase the memory limit via .htaccess does not work on hostmonster atleast, and results in a different fatal error.
  • Trying to increase the memory limit by adding a momory_limit 64MB or some such line in php.ini in your website root folder does not work, as it does not cascade into child folders.
  • What worked in this case was the memory_limit line in a php.ini file inside the wp-admin folder. Go figure.

So, I was finally able to upload my son's first sports day pictures after an hour of troubleshooting. I think I'll postpone my plans of upgrading WordPress itself till next month.  I hope this helps someone battling with a shared hosting memory crisis for PHP or unoptimized WordPress plugins. Make me happy by posting in the comments if this solution saved some of your time.

6 Comments

  1. Thanks! That tip was exactly what I was looking for. I am pretty sure I tried placing the php.ini file everywhere BUT the wp-admin folder, which totally makes sense now that I think about it.

    Cheers!

  2. Sohaib Athar says:

    I’m glad all the time I spent in frustration was not entirely wasted 🙂

  3. Rishi says:

    Thanks for the tip! 🙂

  4. Brian says:

    I’ve been scratching my head on this one for a couple days. I’m using Hostmonster shared hosting and running WordPress 2.2.1 on an older photo gallery site that I haven’t bothered updating. Up until recently, I was using PHP4, but switched to PHP5 through Hostmonster’s PHP config interface, and then of course started having trouble with just this one particular site. Monkeyed with my .htaccess and php.ini files, changed the memory limits and such…no luck. Just read your post and copied my php.ini into the wp-admin directory and what do know? Would NOT have thunk it, thanks for the fix!

  5. Tony Wildish says:

    I don’t know how you figured that out, but I’m glad you did. I was beginning to think I’d have to change hosting service, which I was not looking forward to!

  6. Nicolas says:

    Thanks, that worked like a charm!!