Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


    Cloudron Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular

    Setting memory_limit dynamically in WordPress (Developer) package

    WordPress (Developer)
    2
    7
    274
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d19dotca
      d19dotca last edited by d19dotca

      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.

      --
      Dustin Dauncey
      www.d19.ca

      girish 1 Reply Last reply Reply Quote 2
      • Referenced by  d19dotca d19dotca 
      • girish
        girish Staff @d19dotca last edited by 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).

        d19dotca 2 Replies Last reply Reply Quote 0
        • d19dotca
          d19dotca @girish last edited by

          @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.

          --
          Dustin Dauncey
          www.d19.ca

          1 Reply Last reply Reply Quote 0
          • d19dotca
            d19dotca @girish last edited by d19dotca

            @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.

            --
            Dustin Dauncey
            www.d19.ca

            girish 1 Reply Last reply Reply Quote 0
            • girish
              girish Staff @d19dotca last edited by

              @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>
              
              
              1 Reply Last reply Reply Quote 0
              • d19dotca
                d19dotca last edited by

                @girish did you mean to duplicate your post? lol. Not sure if you meant to provide a different update or not.

                --
                Dustin Dauncey
                www.d19.ca

                girish 1 Reply Last reply Reply Quote 0
                • girish
                  girish Staff @d19dotca last edited by

                  @d19dotca whoops, looks like some network retry from my browser. did not notice! i removed the dup.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB