Memory Limit Problem in WordPress?

Are you getting an error like the one below?

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 40 bytes) in /xxx/wp-includes/wp-db.php on line 1403

You are probably getting this because you do not have enough memory allocated to complete the task. I tried many different options like adding this to the wp-config…

<?php define('WP_MEMORY_LIMIT', '6000M'); ?>

Well that does not work because wordpress is using WP_MAX_MEMORY_LIMIT so you can add the above all you want and change add variations of that call in your htaccess and php.ini file, but trust me it will do no good!

The Reason

You may be asking why does he need so much memory? Well when trying to delete over 1million orders from WooCommerce using the storekit tool the script kept erroring out with the above error we mentioned. This was a localhost setup so it was easy to increase the memory to 6gig to speed things along. It took 37 minutes to delete over 1 millions orders. And NO, just going to the database and dropping the table was not an option because we had so much other info in the table wp_post.

The Solution

Add this snippet to your wp-config file and you should be good to go!

<?php define('WP_MAX_MEMORY_LIMIT', '6000M'); ?>