By default, WordPress enforces a memory limit of 40 MB. This means a single PHP script is allowed to use up to 40 MB of RAM. In certain cases, you may need to increase WordPress’ memory limit to run heavier plugins like WooCommerce or bbPress. To increase WordPress’ memory limit, you can define
WP_MEMORY_LIMIT in your
wp-config.php file using the line below.
define( 'WP_MEMORY_LIMIT', '256M' );
The setting above will allow WordPress to use up to 256 MB of RAM for each script, as long as the
memory_limit setting in your
php.ini file is 256 MB or greater. As is often the case with computing resources, setting a higher memory limit doesn't necessarily increase the performance of your WordPress site. Since
WP_MEMORY_LIMIT controls memory allocation PER SCRIPT, it's actually in your best interest to set it as low as possible to reduce the chance of a rogue script saturating the RAM in your server.
Sometimes, it's a good idea to tailor WordPress’ memory allocation separately for the frontend and backend. That's where
WP_MAX_MEMORY_LIMIT comes in.
WP_MAX_MEMORY_LIMIT allows you to set a different memory limit for WordPress’ administration dashboard. This is useful because certain administration tasks require more RAM. Below is an example of how you can use
define( 'WP_MEMORY_LIMIT', '64M' ); define( 'WP_MAX_MEMORY_LIMIT', '256M');
The setting above will allocate up to 64 MB of RAM per PHP script for processes spawned from WordPress’ frontend, while administration-related scripts from the backend dashboard will be able to use up to 256 MB of RAM.