From 82fe641c42a9a9a8ba69a927c67efc0f9b18845e Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 13 Jul 2019 02:05:54 +0100 Subject: [PATCH] Setup: Make wfMemoryLimit() internal and simplify Bug: T189966 Change-Id: I4fa3d66dbf2e2d05a0d1868329a16dfb1959498f --- includes/GlobalFunctions.php | 27 ++++++++++++--------------- includes/Setup.php | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 5f17ad8627..c6c386c42f 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2756,30 +2756,27 @@ function wfStripIllegalFilenameChars( $name ) { } /** - * Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit + * Raise PHP's memory limit (if needed). * - * @return int Resulting value of the memory limit. + * @internal For use by Setup.php */ -function wfMemoryLimit() { - global $wgMemoryLimit; - $memlimit = wfShorthandToInteger( ini_get( 'memory_limit' ) ); - if ( $memlimit != -1 ) { - $conflimit = wfShorthandToInteger( $wgMemoryLimit ); - if ( $conflimit == -1 ) { +function wfMemoryLimit( $newLimit ) { + $oldLimit = wfShorthandToInteger( ini_get( 'memory_limit' ) ); + // If the INI config is already unlimited, there is nothing larger + if ( $oldLimit != -1 ) { + $newLimit = wfShorthandToInteger( $newLimit ); + if ( $newLimit == -1 ) { wfDebug( "Removing PHP's memory limit\n" ); Wikimedia\suppressWarnings(); - ini_set( 'memory_limit', $conflimit ); + ini_set( 'memory_limit', $newLimit ); Wikimedia\restoreWarnings(); - return $conflimit; - } elseif ( $conflimit > $memlimit ) { - wfDebug( "Raising PHP's memory limit to $conflimit bytes\n" ); + } elseif ( $newLimit > $oldLimit ) { + wfDebug( "Raising PHP's memory limit to $newLimit bytes\n" ); Wikimedia\suppressWarnings(); - ini_set( 'memory_limit', $conflimit ); + ini_set( 'memory_limit', $newLimit ); Wikimedia\restoreWarnings(); - return $conflimit; } } - return $memlimit; } /** diff --git a/includes/Setup.php b/includes/Setup.php index f34b176e68..df53c9976a 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -762,7 +762,7 @@ $ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc' ); // Raise the memory limit if it's too low // Note, this makes use of wfDebug, and thus should not be before // MWDebug::init() is called. -wfMemoryLimit(); +wfMemoryLimit( $wgMemoryLimit ); /** * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+ -- 2.20.1