Memory limit in WordPress

tl;dr: Manually set value or the default values ​​of WP_MEMORY_LIMIT/WP_MAX_MEMORY_LIMIT have no effect if WP_MEMORY_LIMIT/WP_MAX_MEMORY_LIMIT less than or equal to the memory limit of PHP (hereinafter memory_limit called) is. They are used to set too low values ​​of memory_limit dynamically to a recommended minimum.


  • The constant WP_MEMORY_LIMIT can optionally in wp-config.php with define('WP_MEMORY_LIMIT', 'XXXM'); be set.
  • The constant WP_MAX_MEMORY_LIMIT can optionally in wp-config.php with define('WP_MAX_MEMORY_LIMIT', 'XXXM'); be set.
  • Is WP_MEMORY_LIMIT not set, applies to its default value:
    • memory_limit, provided the value of memory_limit cannot be changed dynamically,
    • 64 MB if it is a multisite,
    • 40MB otherwise.
  • Is WP_MAX_MEMORY_LIMIT not set, applies to its default value:
    • memory_limit, provided the value of memory_limit is not dynamically changeable or if it is unbounded (-1) or greater than or equal to 256 MB,
    • 256 MB otherwise .
  • The default values ​​have been raised again and again in the past.
  • WP_MEMORY_LIMIT changed everywhere using the function ini_set() dynamic memory_limit, if WP_MEMORY_LIMIT larger than the current one memory_limit or when WP_MEMORY_LIMIT is unlimited (-1).
  • WP_MAX_MEMORY_LIMIT changed in the backend (more precisely: whenever the function wp_raise_memory_limit() called in different contexts [admin, image]) using the function ini_set() dynamic memory_limit, if WP_MAX_MEMORY_LIMIT larger than the current one memory_limit or when WP_MAX_MEMORY_LIMIT is unlimited (-1).
  • The logic of WP_MAX_MEMORY_LIMIT runs after the logic of WP_MEMORY_LIMIT, so that WP_MEMORY_LIMIT in the frontend and WP_MAX_MEMORY_LIMIT takes effect in the backend.
  • Much of the logic described above is in function wp_initial_constants() (/wp-includes/default-constants.php) as in wp_raise_memory_limit() (/wp-includes/functions.php) instead of.
  • The value memory_limit = XXXM in php.ini Are defined memory_limit (after restarting the web service).
  • The value php_value memory_limit XXXM in .htaccess Are defined memory_limit for all PHP files in the folder or its subfolder in which the .htaccess located.
  • The web server can prevent the value of the memory limit from being changed with ini_set() or from exceeding a specified value (see php_admin_value ).
  • memory_limit applies per process: An increase of memory_limit can cause the number of parallel PHP requests to decrease. The value should therefore be chosen carefully (256 MB, in exceptional cases 512 MB).
  • In the WordPress backend under Tools > Website State, the values ​​of memory_limit (Section: Server), as well as from WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT (section WordPress constants) can be read out.
Back