Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

54117 memory limit changes #8080

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/wp-admin/includes/class-wp-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1476,13 +1476,13 @@ private static function get_wp_constants(): array {
'label' => 'WP_PLUGIN_DIR',
'value' => WP_PLUGIN_DIR,
),
'WP_MEMORY_LIMIT' => array(
'label' => 'WP_MEMORY_LIMIT',
'value' => WP_MEMORY_LIMIT,
'WP_VISITOR_MEMORY_LIMIT' => array(
'label' => 'WP_VISITOR_MEMORY_LIMIT',
'value' => WP_VISITOR_MEMORY_LIMIT,
),
'WP_MAX_MEMORY_LIMIT' => array(
'label' => 'WP_MAX_MEMORY_LIMIT',
'value' => WP_MAX_MEMORY_LIMIT,
'WP_ADMIN_MEMORY_LIMIT' => array(
'label' => 'WP_ADMIN_MEMORY_LIMIT',
'value' => WP_ADMIN_MEMORY_LIMIT,
),
'WP_DEBUG' => array(
'label' => 'WP_DEBUG',
Expand Down
24 changes: 12 additions & 12 deletions src/wp-includes/default-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@ function wp_initial_constants() {
$current_limit_int = wp_convert_hr_to_bytes( $current_limit );

// Define memory limits.
if ( ! defined( 'WP_MEMORY_LIMIT' ) ) {
if ( ! defined( 'WP_VISITOR_MEMORY_LIMIT' ) ) {
if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
define( 'WP_MEMORY_LIMIT', $current_limit );
define( 'WP_VISITOR_MEMORY_LIMIT', $current_limit );
} elseif ( is_multisite() ) {
define( 'WP_MEMORY_LIMIT', '64M' );
define( 'WP_VISITOR_MEMORY_LIMIT', '64M' );
} else {
define( 'WP_MEMORY_LIMIT', '40M' );
define( 'WP_VISITOR_MEMORY_LIMIT', '40M' );
}
}

if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
if ( ! defined( 'WP_ADMIN_MEMORY_LIMIT' ) ) {
if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
define( 'WP_ADMIN_MEMORY_LIMIT', $current_limit );
} elseif ( -1 === $current_limit_int || $current_limit_int > 256 * MB_IN_BYTES ) {
define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
} elseif ( wp_convert_hr_to_bytes( WP_MEMORY_LIMIT ) > 256 * MB_IN_BYTES ) {
define( 'WP_MAX_MEMORY_LIMIT', WP_MEMORY_LIMIT );
define( 'WP_ADMIN_MEMORY_LIMIT', $current_limit );
} elseif ( wp_convert_hr_to_bytes( WP_VISITOR_MEMORY_LIMIT ) > 256 * MB_IN_BYTES ) {
define( 'WP_ADMIN_MEMORY_LIMIT', WP_VISITOR_MEMORY_LIMIT );
} else {
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
define( 'WP_ADMIN_MEMORY_LIMIT', '256M' );
}
}

// Set memory limits.
$wp_limit_int = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
$wp_limit_int = wp_convert_hr_to_bytes( WP_VISITOR_MEMORY_LIMIT );
if ( -1 !== $current_limit_int && ( -1 === $wp_limit_int || $wp_limit_int > $current_limit_int ) ) {
ini_set( 'memory_limit', WP_MEMORY_LIMIT );
ini_set( 'memory_limit', WP_VISITOR_MEMORY_LIMIT );
}

if ( ! isset( $blog_id ) ) {
Expand Down
10 changes: 5 additions & 5 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7803,7 +7803,7 @@ function wp_raise_memory_limit( $context = 'admin' ) {
return false;
}

$wp_max_limit = WP_MAX_MEMORY_LIMIT;
$wp_max_limit = WP_ADMIN_MEMORY_LIMIT;
$wp_max_limit_int = wp_convert_hr_to_bytes( $wp_max_limit );
$filtered_limit = $wp_max_limit;

Expand All @@ -7816,7 +7816,7 @@ function wp_raise_memory_limit( $context = 'admin' ) {
* like updates. Memory limits when processing images (uploaded or edited by
* users of any role) are handled separately.
*
* The `WP_MAX_MEMORY_LIMIT` constant specifically defines the maximum memory
* The `WP_ADMIN_MEMORY_LIMIT` constant specifically defines the maximum memory
* limit available when in the administration back end. The default is 256M
* (256 megabytes of memory) or the original `memory_limit` php.ini value if
* this is higher.
Expand All @@ -7838,7 +7838,7 @@ function wp_raise_memory_limit( $context = 'admin' ) {
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit Maximum memory limit to allocate for image processing.
* Default `WP_MAX_MEMORY_LIMIT` or the original
* Default `WP_ADMIN_MEMORY_LIMIT` or the original
* php.ini `memory_limit`, whichever is higher.
* Accepts an integer (bytes), or a shorthand string
* notation, such as '256M'.
Expand All @@ -7853,7 +7853,7 @@ function wp_raise_memory_limit( $context = 'admin' ) {
* @since 6.3.0
*
* @param int|string $filtered_limit Maximum memory limit to allocate for WP-Cron.
* Default `WP_MAX_MEMORY_LIMIT` or the original
* Default `WP_ADMIN_MEMORY_LIMIT` or the original
* php.ini `memory_limit`, whichever is higher.
* Accepts an integer (bytes), or a shorthand string
* notation, such as '256M'.
Expand All @@ -7872,7 +7872,7 @@ function wp_raise_memory_limit( $context = 'admin' ) {
* @since 4.6.0
*
* @param int|string $filtered_limit Maximum memory limit to allocate for this context.
* Default WP_MAX_MEMORY_LIMIT` or the original php.ini `memory_limit`,
* Default WP_ADMIN_MEMORY_LIMIT` or the original php.ini `memory_limit`,
* whichever is higher. Accepts an integer (bytes), or a
* shorthand string notation, such as '256M'.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*/
global $blog_id;

// Set initial default constants including WP_MEMORY_LIMIT, WP_MAX_MEMORY_LIMIT, WP_DEBUG, SCRIPT_DEBUG, WP_CONTENT_DIR and WP_CACHE.
// Set initial default constants including WP_VISITOR_MEMORY_LIMIT, WP_ADMIN_MEMORY_LIMIT, WP_DEBUG, SCRIPT_DEBUG, WP_CONTENT_DIR and WP_CACHE.
wp_initial_constants();

// Register the shutdown handler for fatal errors as soon as possible.
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/includes/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@
*/
define( 'DISABLE_WP_CRON', true );

define( 'WP_MEMORY_LIMIT', -1 );
define( 'WP_MAX_MEMORY_LIMIT', -1 );
define( 'WP_VISITOR_MEMORY_LIMIT', -1 );
define( 'WP_ADMIN_MEMORY_LIMIT', -1 );

define( 'REST_TESTS_IMPOSSIBLY_HIGH_NUMBER', 99999999 );

Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/tests/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,14 +1158,14 @@ public function test_wp_ext2type() {
/**
* Tests raising the memory limit.
*
* Unfortunately as the default for 'WP_MAX_MEMORY_LIMIT' in the
* Unfortunately as the default for 'WP_ADMIN_MEMORY_LIMIT' in the
* test suite is -1, we can not test the memory limit negotiations.
*
* @ticket 32075
*/
public function test_wp_raise_memory_limit() {
if ( -1 !== WP_MAX_MEMORY_LIMIT ) {
$this->markTestSkipped( 'WP_MAX_MEMORY_LIMIT should be set to -1.' );
if ( -1 !== WP_ADMIN_MEMORY_LIMIT ) {
$this->markTestSkipped( 'WP_ADMIN_MEMORY_LIMIT should be set to -1.' );
}

$ini_limit_before = ini_get( 'memory_limit' );
Expand All @@ -1174,7 +1174,7 @@ public function test_wp_raise_memory_limit() {

$this->assertSame( $ini_limit_before, $ini_limit_after );
$this->assertFalse( $raised_limit );
$this->assertEquals( WP_MAX_MEMORY_LIMIT, $ini_limit_after );
$this->assertEquals( WP_ADMIN_MEMORY_LIMIT, $ini_limit_after );
}

/**
Expand Down
Loading