3/26/2014

WordPress: Memory problems & Fatal errors from Plug-In & too many Tags

I'm fairly new to WordPress and having a disastrous time moving from a test site to our company's site.

Just when I get to the point where everything ought to work. I get a blank screen. Or, I get this message.

Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 962977 bytes) in /var/www/.../wp-includes/wp-db.php on line 880

That number is exactly 40 Megabytes. This appears to be the default setting for WordPress.

After some research, I've found several solutions.

1) JetPack uses a lot of memory.
Even if you deactivate all the options, JetPack alone uses 4 or 5 MB.
Solution: Either deactivate JetPack  completely, or at least deactivate all of functions that you don't need. To deactivate a function, click on the [More Info] button, and the [Deactivate] button will appear.
2) If you can't access your WP Admin panel because of the error message, change the name of the JetPack folder.
FTP to your server and change the name of the "/wp-content/plugins/jetpack" folder to "jetpack-DEACTIVATED".
Now, you may be able to get into your WP Admin. 
3) You may also want to check your PHP memory allowance.
WordPress is written in a language called php. If you can create a new testmemory.php page and upload it to your server with this as the only line of code:
 <?php phpinfo(); ?> 
You may see a PHP Core value called "memory_limit." If the Master value is over 40MB, you should be able to increase your memory limit.
4) Probably the easiest solution is to open your "wp-config.php" file.
Open the file in a text editor.
Add this line in to see if it helps. You can make the number higher if needed.
define('WP_MEMORY_LIMIT', '64M');
5) Too many "tags" on your posts.
I like to tag my posts so that they relate to each other. However, some people use way too many. If your tag is likely NEVER going to match another tag, then don't create a new tag.
If you'd like to see a full list of your Wordpress tags, and how many times they have been used, you may want to run this SQL query on your database (assuming your tables use "wp_" as the prefix).
SELECT terms.term_id,  COUNT(tr.term_taxonomy_id) as timesUsed  FROM wp_terms terms JOIN wp_term_taxonomy tt  ON tt.term_id = terms.term_id JOIN wp_term_relationships tr  ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = "post_tag"  GROUP BY terms.term_id   ORDER BY COUNT(tr.term_taxonomy_id) DESC, terms.term_id ASC;
Sorry, I don't have any SQL code written to auto delete the tags that are lonely single-usage entries.
What I can tell you is that with no tags, our setup uses 22 MB. With all 15, 600 tags, the memory usage triples to 63 MB. Deleting 10,000 of the orphaned tags that had no match dropped us back to 37 MB. 
Seriously, WordPress creators, what are you thinking with this wasteful programming? For TAGS -- all they are is tags? 
This is just a bad programming decision on somebody's part at WordPress. There's one field in the wp_options table, also called, wp_options. I'm assuming it is a string of data that includes all of the settings that are being loaded. I pasted it into a blank Word document -- guess how long that one database string entry is... 338 pages long!!! Someone get a clue.
6) Find out how much memory is being used.
You can enter a php command to see how much memory is being used somewhere in your administration scripts. 
I edited the "/wp-admin/index.php" file to  include this line just above the final 2 lines that say "<?php require ( ABSPATH . 'wp-admin...."
<?php echo "Memory usage: " . number_format( memory_get_usage(),0, $dec_point = '.',$thousands_sep = ',') . " KB (" . number_format( (memory_get_usage()/1048576),1, $dec_point = '.',$thousands_sep = ',') . " MB)"; ?>
Now, on the main Dashboard, I see a line that reads: "Memory usage: 36,709,872 KB (35.0 MB)" 
7) Don't be inefficient. Maybe you can use unlimited memory. Maybe you can have unlimited tags. Maybe your host doesn't care about performance. Personally, I hate knowing that I'm going to bump up against my limit again at some unexpected time. So, I just say, be aware and cautious about your memory usage now that you know. Delete plug-ins you don't need. Do you need all of JetPack for a Twitter widget? -- when you get away with a Text widget that contains code directly from Twitter. Stuff like that should save you some memory headaches, I think.

No comments :

Post a Comment