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.