I’m hoping to carve out some time soon to get back to the garage and return to tinkering with WordPress. To that end, I spent some time categorizing new and old posts, so I have a collection now of things blogged about using WordPress at http://cogdogblog.com/wp.
Here at CogDogBlog, I’ve had some challenges with what I think is memory issues- lots of 404/not found on admin pages, and worse, strongs of deadly 500 Internal Server errors for visitors. Not good. No, not good. My web server error logs are full of the not very helpful “premature end of script headers” for index.php. You could spend years combing through the google results for this.
What follows is not a definitive answer to this situation, just some guesses and results of my attempts to make it stop. To fast forward, WordPress often needs more memory for PHP to do its work that the default settings allow. You can adjust it if you have a self-hosted site.
“Premature end of script headers” means (I think) that PHP died before it could finish returning information; often it did manage to complete the task at hand. Shared hosting sites usually rus a service that kills jobs that are eating too much memory. But the same error can occur from whacky or corrupt plugins or even templates.
After some reading and poking around, I got a sense my blog was dealing with running out of memory- I got some good ideas from a post on WordPress Shared Hosting Performance and a string of comments on a premature script headers part of the WordPress Codex.
From these posts, I gave the TPC! Memory Usage plugin a spin. At a first cut, it provides stats on your blog’s memory usage and settings (though this info is readily available elsewhere (simplest is a basic php script that uses the phpinfo function to output environment settings; best not to leave this on a server as it reveals path info that can be used by ne’er do wells).
But what the plugin does is alert you when your site is using more memory for PHP that it is allocated– and I got a flood of these, indicating that my site was regularly using a tad over the default 32 Mb of memory.
The key is to know how much memory your server can allocate to php — in my case, the max was 90 Mb. The fix is pretty easy, an edit to my wp-config.php file and add
I changed the options in the TPC! Memory Usage plugin to message me only when the memory exceeded 64, but I still has getting emails when it went over 32 Mb (adding a specific email address seemed to clear this up), but once I had made the changes, I just de-activated the plugin.
Before that I was seeing than the typical usage on my site was about 35 Mb, some 15% of the total (90) that is technically available.
As a rule, its best to be sparing with plugins, they all add load to your site.
After this change I saw a drastic decrease in the “premature script headers” message in my error logs.
I am still having an occasional issue with the blog going under buried by 500 Internal server messages, and am trying to isolate what is happening. Oddly, the only way to clear it is to go in the database, and edit the wp_options entry for active plugins to use one less plugin, save, and then return it to the previous values (I know, that sound crazy, but it works- maybe it is some clash between server errors and W3 Total Cache??).
I have no idea if I am correct about any of this, but it does seem that 32Mb as the default setting for WordPress memory is borderline, or at least it is for my blog.
But its no fun when your memory fails! It HURTS!