[wp-trac] [WordPress Trac] #49329: memory_limit in site health is not really correct, value is taken from wp_raise_memory_limit

WordPress Trac noreply at wordpress.org
Thu Jan 30 14:26:05 UTC 2020


#49329: memory_limit in site health is not really correct, value is taken from
wp_raise_memory_limit
----------------------------+--------------------------------------------
 Reporter:  espiat          |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Site Health     |    Version:  5.3.2
 Severity:  normal          |   Keywords:  reporter-feedback dev-feedback
  Focuses:  administration  |
----------------------------+--------------------------------------------
 Hi.

 this is my first ticket.

 Somebody saw that the memory_limit in the site health is not the value
 from the php.ini

 So I started looking for it.

 **Problem:**
 The reason is the function wp_raise_memory_limit

 This is called here:
 https://github.com/WordPress/WordPress/blob/16b8d91baa830fd88eed7d6312477e4f0891798c
 /wp-
 admin/admin.php?fbclid=IwAR2pQTBHMaEZAvm1xpXSgfgBDh_ubgYrkMhGtDbFibs9Gom7CIha2kLF3-U#L156

 And defined here:
 https://github.com/WordPress/WordPress/blob/001ffe81fbec4438a9f594f330e18103d21fbcd7
 /wp-includes/functions.php#L6784

 So if you are logged in as admin, the memory_limit will be raised to 256M,
 if this can be changed and the value in wp-config.php is not higher.

 The value is therefore not specified correctly in Site Health, because it
 may have a different value in the frontend and for other users (apart from
 admin).

 The Plugin Query Monitor also shows this value with a trick (more:
 https://github.com/johnbillion/query-
 monitor/blob/49485f9359cc57efdc3f4d2d86d342a43e6b6dcf/README.md#a-note-on-
 query-monitors-implementation)

 Then I tried in the function (wp_raise_memory_limit) with if queries

 'site-health' === $ screen-> id
 or
 $ site_health_screen = get_current_screen ()
 to keep the real memory_limit

 But that didn't work.

 The raise function is called so early, that it is hard to get the real
 memory_limit.

 **my Solution:**
 (i currently doent know how to add "real" commit changes here in this trac
 system)

 Adding the global var and call the value first in the
 wp_raise_memory_limit function
 (https://github.com/WordPress/WordPress/blob/001ffe81fbec4438a9f594f330e18103d21fbcd7
 /wp-includes/functions.php#L6784)
 {{{#!php
 <?php

 function wp_raise_memory_limit( $context = 'admin'  ) {

         global $server_memory_limit;
         $server_memory_limit = ini_get( 'memory_limit' );


         // Exit early if the limit cannot be changed.
 ...
 }}}

 Add the global var in the function 'debug_data()' (line:
 https://github.com/WordPress/WordPress/blob/001ffe81fbec4438a9f594f330e18103d21fbcd7
 /wp-admin/includes/class-wp-debug-data.php#L32'

 {{{#!php
 <?php
 static function debug_data() {
                 global $wpdb;
                 global $server_memory_limit;
 }}}


 After including the global server memory we can return an extra row in the
 site health table
 (https://github.com/WordPress/WordPress/blob/001ffe81fbec4438a9f594f330e18103d21fbcd7
 /wp-admin/includes/class-wp-debug-data.php#L650):


 {{{#!php
 <?php
 $info['wp-server']['fields']['memory_limit_server']        = array(
                                 'label' => __( 'PHP memory limit (server
 setting)' ),
                                 'value' => $server_memory_limit,
                         );
 }}}

 That's it.

 Thanks in advance for the feedback

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49329>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list