[wp-trac] [WordPress Trac] #32075: Only set WP_MAX_MEMORY_LIMIT by default when its greater than memory_limit

WordPress Trac noreply at wordpress.org
Sun Apr 10 02:06:18 UTC 2016


#32075: Only set WP_MAX_MEMORY_LIMIT by default when its greater than memory_limit
------------------------------------+-----------------------------
 Reporter:  danielbachhuber         |       Owner:
     Type:  defect (bug)            |      Status:  new
 Priority:  normal                  |   Milestone:  Future Release
Component:  Bootstrap/Load          |     Version:  3.2
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:
------------------------------------+-----------------------------

Comment (by jrf):

 @mensmaximus

 > How usefull can it be to set WP_MAX_MEMORY_LIMIT to 256M by default if
 the allocated memory ( ini_get( 'memory_limit' ) ) is less than 256M?

 The PHP `memory_limit` ini value can be changed at runtime which is what
 this function tries to do.

 > What would happen if a plugin developer would rely on the constants
 value and this value exceeds the memory allocated by the server (and
 restricted by the hosting company)?

 You can never rely on the changing at runtime to succeed. This function
 ''*attempts*'' to raise the memory limit, there is no guarantee that it
 will. `ini_set()` will return `false` if it fails to change the value.

 As a plugin developer, you should only rely on the success of this if you
 have control of the server your plugin runs on. This will generally only
 be the case for one-off, custom plugins.

 In all other circumstances: if you get a lot of complaints from users
 about fatal errors related to memory usage, trying to lower the memory
 usage of your plugin is the safer (and better) practice.

 > Imho the WP_MAX_MEMORY_LIMIT constant should never report a larger
 amount of memory than the maximum allocatable memory.

 AFAIK there is no reliable way to find out the maximum allocatable memory
 on the server, so there is no way I can think of to take that into account
 when setting the constant, quite apart from the fact that the constant can
 be defined in `wp-config.php` outside of our control.

 N.B.: There is a `memory_get_peak_usage( true )` PHP function, but the
 output of this is AFAIK not reliable across all servers.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32075#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list