Setting memory_limit dynamically in WordPress (Developer) package
-
I've been experimenting the past few months with WP memory limits. I actually just recently found a way to dynamically set it according to the php.ini settings, and it works quite well. I'm curious... can (or should) this be added dynamically to the WordPress package itself to be set this way?
define( 'WP_MEMORY_LIMIT', ini_get( 'memory_limit' ) );
We all know the memory limit should generally be greatly increased to at least 128M but usually recommended at 256M for
WP_MEMORY_LIMIT
so why not just have it set dynamically to the php.ini file / defaults which are higher than the 40M default (which is far too low)?This is slightly related to an older post I had actually here for reference: https://forum.cloudron.io/topic/2714/where-is-memory_limit-and-wp_memory_limit-set/5?_=1636224450803 where I asked if this could be done, was told that it always defaults to 40M, but if we add in the line above then that can be fixed to behave in a more recommended manner. I believe the recommendation above is the solution to what you thought was a limitation @girish.
-
-
@d19dotca I think this increases WP default memory limit to 128MB doesn't it? The default Cloudron app container allocation is 256MB and the prefork configuration is setup with 2 server and max 6 iirc. These values are set with the 40MB default in mind.
In the past, I tried all sorts of things to set the limits based on the container memory limit. But it always fails in some case, so I though it's best to just leave the values as defaults. I think atleast for WP there are gazillion sites saying 40MB is default and how to edit wp-config.php to change it (not sure if this matters).
-
@girish I don't think that's quite correct. In my testing, the default WP memory limit is 40 MB according to the WordPress system info if I don't specify a memory limit in php.ini and don't specify the memory limit in wp-config.php, the 40 MB default is used which is not the recommended setup. This is why I was suggesting the wp-config.php be edited in the package to point to the defaults of php.ini which is the 128 MB you mentioned. Adding that line to the wp-config.php file will automatically make WordPress memory limit match the php.ini setting.
-
@girish said in Setting memory_limit dynamically in WordPress (Developer) package:
setup with 2 server and max 6 iirc
Just curious where those numbers come from. Here is the
mpm_prefork.conf
file contents:# Restart the app if you make changes to this file <IfModule mpm_prefork_module> # On startup, start these many servers StartServers 2 # At any given time, keep atleast these many servers MinSpareServers 2 # At any given time, keep atmost these many idle servers (this is always >= MinSpareServers+1) MaxSpareServers 3 # Maximum number of servers at any given instant. Requests will be queued after this MaxRequestWorkers 15 # Recycle process after handling these many requests. This protected against accidental memory leaks MaxConnectionsPerChild 100 </IfModule>
I think this means we can have a minimum of 2 Apache server processes and a maximum of 15.
-
@d19dotca indeed. looks like the managed version has slightly different values - https://git.cloudron.io/cloudron/wordpress-managed-app/-/blob/master/apache/mpm_prefork.conf (don't think it's intentional that they are different).
<IfModule mpm_prefork_module> # On startup, start these many servers StartServers 2 # At any given time, keep atleast these many servers MinSpareServers 2 # At any given time, keep atmost these many idle servers (this is always >= MinSpareServers+1) MaxSpareServers 3 # Maximum number of servers at any given instant. Requests will be queued after this MaxRequestWorkers 6 # Recycle process after handling these many requests. This protected against accidental memory leaks MaxConnectionsPerChild 100 </IfModule>