I know that it is possible to restrict (or extend) the memory usage of the entire WP site using:

define('WP_MEMORY_LIMIT', '64M')

Is it possible to do the same for only one plugin that the website uses ?

2 Answers 2


No and even if you could, if the plugin ran out of available memory then the entire page generation would stop due to the fatal error.

You're better off fixing the plugin itself to not use as much memory or to just further increase the total memory allocated to WordPress/PHP.


Generally spoken, no, it is not possible for a particular plugin only. The plugin runs in the whole wordpress PHP process (normally) and therefore it shares the memory limit setting with the rest.

You can however try to limit the memory before each time the plugin is called. That would be prior any hook of it (that's possible) and then in the beginning prior the inclusion (that's much harder to achieve).

The define of WP_MEMORY_LIMIT gets overwritten by the way, so setting that constant to something is not useful if you actually want to limit memory.

If you do not fear to deal with system internals, you can however limit the memory for the whole process properly as well as if you like it experimental, you can give runkit a try and execute the plugins code therein - somehow.

  • What do you mean when you say that WP_MEMORY_LIMIT gets overwritten? Since it's a constant, its value can't change once it's been set. wp_initial_constants() only sets the value if it hasn't already been set in wp-config.php.
    – Ian Dunn
    Oct 26, 2011 at 17:40
  • @Ian Dunn: Sure, the constant does not get overwritten, but the value it carries will get before it's being applied to the memory limit call. At least it was, this has been improved some time ago in trunk, I think WP 3.2 benefits from these changes.
    – hakre
    Oct 26, 2011 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.