What is the difference in the WP memory limits?

I have seen this question PHP Memory Limit vs. WP Memory Limit and it has a really poor answer and the question isn't that good either.

I am on a dedicated server and can do whatever I want. I want to make sure our site runs as fast as possible and had define( 'WP_MAX_MEMORY_LIMIT', '1024M' ); in our config.

But then our theme had an update and I saw a screen that showed our PHP memory was 1024MB and our WP memory was 40MB. I was like WHAT THE HELL. So I added into the config define('WP_MEMORY_LIMIT', '1024M'); and saw the WP memory had gone up to 1024MB.

So without beating around the bush can I get a very technical answer about what the difference in these two settings are. Did me changing the WP memory limit really have any effect on my site? If so are these setting named horribly? (I fully understand how to allocate memory in PHP - looking at what limitations each setting put on my site.)

Addendum: So if my php.ini has memory limit set to 1024M and WP has no settings I am assuming it can use 1024m or the default of 40M? Then what if there are multiple instances of WP running on the site? Do they each get 1024M or total? Is there a way to set one instance of WP to use less memory? For instance if I have 5 WP sites on a server can I set one to use a max of 64M, another 1024M, and so on?

Topic wp-config memory php Wordpress

Category Web


WP_MEMORY_LIMIT is max memory your WordPress will use while generating a http response, I mean when you a hit a URL, WordPress content has to be generated (html, css, js etc) before it is delivered, Hence any Server side Rendering/creating of the webpage shouldn't use more than WP_MEMORY_LIMIT(I have this set to 64MB.) so if 4 simultaneous URL hits are received on WordPress server then 256MB of memory will be consumed(64x4). Once the page is rendered/ generated and sent over http response this memory is freed.


Technically, they are for only one purpose: override memory_limit value in php.ini.

The difference is:

  • WP_MEMORY_LIMIT will permanently override memory_limit if its value is greater than the current value in php.ini.

  • WP_MAX_MEMORY_LIMIT will temporarily override memory_limit with whatever value you defined. And it only happens in some events such as unzip file while installing/upgrading themes, plugins..., editing/previewing images...


Max is used on the admin side, WP_MEMORY_LIMIT is used on the front end. Don't increase the memory available more than you need to or you'll run the risk of running out of RAM if you have too many simultaneous hits on pages.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.