WordPress & PHP memory-related notes
-
I was recently experimenting a bit with php.ini settings and memory constants in the wp-config.php. Here is what I learned which I had found confusing before, so wanting to share this in case anyone didn't know this already:
When looking at the Tools > Site Health > Info page in WordPress...
- The
PHP memory limit
value (under Server tab) comes from thememory_limit
set in the php.ini file. - The
WP_MAX_MEMORY_LIMIT
value (under WordPress Constants tab) also comes from thememory_limit
set in the php.ini file when theWP_MAX_MEMORY_LIMIT
isn't also defined in the wp-config.php file. If theWP_MAX_MEMORY_LIMIT
is defined in the wp-config.php file, then this overrides thememory_limit
parameter set in the php.ini file. - The
WP_MEMORY_LIMIT
value (under WordPress Constants tab) comes from theWP_MEMORY_LIMIT
defined in the wp-config.php file (this is hard-coded). If not defined, it defaults to40M
.
I would recommend increasing
WP_MEMORY_LIMIT
closer to the overall app memory limit by adding something like this to your wp-config.php file:define( 'WP_MEMORY_LIMIT', '2G' );
for a 2 GB memory limit to WordPress for example.I had found it confusing earlier as to where each parameter was defined and how it was set (and what the defaults are). Hopefully this helps others for the future too.
- The