Commit ff7f9fbcbd3 for woocommerce
commit ff7f9fbcbd3ab9532df87fcab46200f4d63412ba
Author: Jorge A. Torres <jorge.torres@automattic.com>
Date: Mon Oct 12 12:30:58 2026 -0500
Fix the low memory warning when PHP has no memory limit (#69464)
diff --git a/plugins/woocommerce/changelog/32961-fix-unlimited-memory-limit-warning b/plugins/woocommerce/changelog/32961-fix-unlimited-memory-limit-warning
new file mode 100644
index 00000000000..7f13de61382
--- /dev/null
+++ b/plugins/woocommerce/changelog/32961-fix-unlimited-memory-limit-warning
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Show "No limit" instead of a low memory warning on the Status page when PHP has no memory limit.
diff --git a/plugins/woocommerce/includes/admin/views/html-admin-page-status-report.php b/plugins/woocommerce/includes/admin/views/html-admin-page-status-report.php
index 87613bd29c6..1f8ac75f1d7 100644
--- a/plugins/woocommerce/includes/admin/views/html-admin-page-status-report.php
+++ b/plugins/woocommerce/includes/admin/views/html-admin-page-status-report.php
@@ -229,7 +229,9 @@ if ( file_exists( $plugin_path ) ) {
<td class="help"><?php echo wc_help_tip( esc_html__( 'The maximum amount of memory (RAM) that your site can use at one time.', 'woocommerce' ) ); ?></td>
<td>
<?php
- if ( $environment['wp_memory_limit'] < 67108864 ) {
+ if ( '-1' === ini_get( 'memory_limit' ) ) {
+ echo '<mark class="yes">' . esc_html__( 'No limit', 'woocommerce' ) . '</mark>';
+ } elseif ( $environment['wp_memory_limit'] < 67108864 ) {
/* Translators: %1$s: Memory limit, %2$s: Docs link. */
echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( esc_html__( '%1$s - We recommend setting memory to at least 64MB. See: %2$s', 'woocommerce' ), esc_html( size_format( $environment['wp_memory_limit'] ) ), '<a href="https://wordpress.org/support/article/editing-wp-config-php/#increasing-memory-allocated-to-php" target="_blank">' . esc_html__( 'Increasing memory allocated to PHP', 'woocommerce' ) . '</a>' ) . '</mark>';
} else {
diff --git a/plugins/woocommerce/includes/class-wc-tracker.php b/plugins/woocommerce/includes/class-wc-tracker.php
index e1212884567..36423bbc7d1 100644
--- a/plugins/woocommerce/includes/class-wc-tracker.php
+++ b/plugins/woocommerce/includes/class-wc-tracker.php
@@ -465,12 +465,13 @@ class WC_Tracker {
private static function get_wordpress_info() {
$wp_data = array();
- $memory = wc_let_to_num( WP_MEMORY_LIMIT );
+ $memory = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
if ( function_exists( 'memory_get_usage' ) ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- False positive.
- $system_memory = wc_let_to_num( @ini_get( 'memory_limit' ) );
- $memory = max( $memory, $system_memory );
+ $system_memory = @wc_get_container()->get( LegacyProxy::class )->call_function( 'ini_get', 'memory_limit' );
+ // Use 32G for no limit (-1), matching the system status REST API.
+ $memory = max( $memory, wp_convert_hr_to_bytes( '-1' === $system_memory ? '32G' : $system_memory ) );
}
// WordPress 5.5+ environment type specification.
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
index 2b6fd7dcc72..c3fe2ceca74 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
@@ -17,6 +17,7 @@ use Automattic\WooCommerce\Utilities\{ LoggingUtil, OrderUtil, PluginUtil };
use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
use Automattic\WooCommerce\Enums\{ DefaultCustomerAddress, TaxBasedOn, TaxDisplayMode };
use Automattic\WooCommerce\Internal\Features\FeaturesController;
+use Automattic\WooCommerce\Proxies\LegacyProxy;
/**
* System status controller class.
@@ -191,7 +192,7 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
'readonly' => true,
),
'wp_memory_limit' => array(
- 'description' => __( 'WordPress memory limit.', 'woocommerce' ),
+ 'description' => __( 'WordPress memory limit in bytes, or at least 32G if there is no memory limit.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view' ),
'readonly' => true,
@@ -1027,9 +1028,11 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
}
// WP memory limit.
- $wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT );
+ $wp_memory_limit = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
if ( function_exists( 'memory_get_usage' ) ) {
- $wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
+ $php_memory_limit = @wc_get_container()->get( LegacyProxy::class )->call_function( 'ini_get', 'memory_limit' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
+ // Use 32G for no limit (-1) so numeric comparisons keep working.
+ $wp_memory_limit = max( $wp_memory_limit, wp_convert_hr_to_bytes( '-1' === $php_memory_limit ? '32G' : $php_memory_limit ) );
}
// Test POST requests.
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php b/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php
index e6f71de1f2b..92d2796cd13 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php
@@ -938,6 +938,28 @@ class WC_Tracker_Test extends \WC_Unit_Test_Case {
wc_get_container()->get( \Automattic\WooCommerce\Internal\AddressProvider\AddressProviderController::class )->init();
}
+ /**
+ * @testdox Should report the PHP memory limit, using 32 GB when PHP has no limit.
+ *
+ * @testWith ["-1", "32 GB"]
+ * ["2G", "2 GB"]
+ * ["268435456", "256 MB"]
+ *
+ * @param string $php_memory_limit The PHP memory_limit ini value.
+ * @param string $expected The expected reported memory limit.
+ */
+ public function test_get_tracking_data_reports_php_memory_limit( string $php_memory_limit, string $expected ): void {
+ $this->register_legacy_proxy_function_mocks(
+ array(
+ 'ini_get' => fn() => $php_memory_limit,
+ )
+ );
+
+ $tracking_data = WC_Tracker::get_tracking_data();
+
+ $this->assertSame( $expected, $tracking_data['wp']['memory_limit'] );
+ }
+
/**
* Helper method to register a mock address provider.
*/
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller-test.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller-test.php
index 5b32a4fe917..013a97ae3e8 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller-test.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller-test.php
@@ -206,4 +206,26 @@ class WC_REST_System_Status_V2_Controller_Test extends WC_REST_Unit_Test_Case {
return array_column( $response->get_data()['inactive_plugins'], 'plugin' );
}
+
+ /**
+ * @testdox Should report the PHP memory limit in bytes, using 32 GB when PHP has no limit.
+ *
+ * @testWith ["-1", 34359738368]
+ * ["2G", 2147483648]
+ * ["268435456", 268435456]
+ *
+ * @param string $php_memory_limit The PHP memory_limit ini value.
+ * @param int $expected The expected reported memory limit in bytes.
+ */
+ public function test_get_environment_info_reports_php_memory_limit( string $php_memory_limit, int $expected ): void {
+ $this->register_legacy_proxy_function_mocks(
+ array(
+ 'ini_get' => fn() => $php_memory_limit,
+ )
+ );
+
+ $environment = $this->sut->get_environment_info_per_fields( array() );
+
+ $this->assertSame( $expected, $environment['wp_memory_limit'] );
+ }
}