From 1d5874a8c7cd225a92f989f510ae2a7467ea382c Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 4 Aug 2009 02:47:39 +0000 Subject: [PATCH] (bug 16084) Default memory limit should be increased --- RELEASE-NOTES | 2 ++ config/index.php | 16 ++++------------ includes/DefaultSettings.php | 5 +++++ includes/GlobalFunctions.php | 9 +++++++++ includes/Setup.php | 10 +++++++++- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 517922151c..cfff529a67 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -79,6 +79,7 @@ this. Was used when mwEmbed was going to be an extension. * (bug 19907) $wgCrossSiteAJAXdomains and $wgCrossSiteAJAXdomainsRegex added to control which external domains may access the API via cross-site AJAX. * $wgMaintenanceScripts for extensions to add their scripts to the default list +* $wgMemoryLimit has been added, default value '50M' === New features in 1.16 === @@ -386,6 +387,7 @@ this. Was used when mwEmbed was going to be an extension. style that specifies the media attribute as screen. This is done to resolve and issue with Opera (bug 18497) where fullscreen mode is assumed to be projection mode and the style sheet for screen media is no longer used. +* (bug 16084) Default memory limit has be increased to 50M, see $wgMemoryLimit == API changes in 1.16 == diff --git a/config/index.php b/config/index.php index 598e356fe4..cb83d12390 100644 --- a/config/index.php +++ b/config/index.php @@ -466,21 +466,16 @@ if( !function_exists( 'preg_match' ) ) Perl-compatible regular expression functions." ); $memlimit = ini_get( "memory_limit" ); -$conf->raiseMemory = false; if( empty( $memlimit ) || $memlimit == -1 ) { print "
  • PHP is configured with no memory_limit.
  • \n"; } else { print "
  • PHP's memory_limit is " . htmlspecialchars( $memlimit ) . ". "; - $n = intval( $memlimit ); - if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) { - $n = intval( $m[1] * (1024*1024) ); - } - if( $n < 20*1024*1024 ) { - print "Attempting to raise limit to 20M... "; - if( false === ini_set( "memory_limit", "20M" ) ) { + global $wgMemoryLimit; + if( wfParseMemoryLimit( $memlimit ) < wfParseMemoryLimit( $wgMemoryLimit ) ) { + print "Attempting to raise limit to " . htmlspecialchars( $wgMemoryLimit ) . "... "; + if( false === ini_set( "memory_limit", $wgMemoryLimit ) ) { print "failed.
    " . htmlspecialchars( $memlimit ) . " seems too low, installation may fail!"; } else { - $conf->raiseMemory = true; print "ok."; } } @@ -1890,9 +1885,6 @@ set_include_path( implode( PATH_SEPARATOR, \$path ) . PATH_SEPARATOR . get_inclu require_once( \"\$IP/includes/DefaultSettings.php\" ); -# If PHP's memory limit is very low, some operations may fail. -" . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . " - if ( \$wgCommandLineMode ) { if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) { die( \"This script must be run from the command line\\n\" ); diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index d16d97aaf3..d7a0e3ebff 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4151,3 +4151,8 @@ $wgCrossSiteAJAXdomains = array(); */ $wgCrossSiteAJAXdomainsRegex = false; +/** + * The minimum amount of memory that MediaWiki "needs"; MediaWiki will try to raise PHP's memory limit if it's below this amount. + */ +$wgMemoryLimit = "50M"; + diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3fc61e69aa..2dba0d0e86 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3193,6 +3193,15 @@ function wfObjectToArray( $object, $recursive = true ) { return $array; } +/* Parse PHP's silly format for memory limits */ +function wfParseMemoryLimit( $memlimit ) { + $n = intval( $memlimit ); + if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) { + $n = intval( $m[1] * (1024*1024) ); + } + return $n; +} + /* Get the normalised IETF language tag * @param $code String: The language code. * @return $langCode String: The language code which complying with BCP 47 standards. diff --git a/includes/Setup.php b/includes/Setup.php index 0021f5f9eb..462e201899 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -149,7 +149,15 @@ require_once( "$IP/includes/ImageFunctions.php" ); require_once( "$IP/includes/StubObject.php" ); wfProfileOut( $fname.'-includes' ); wfProfileIn( $fname.'-misc1' ); - +# Raise the memory limit if it's too low +global $wgMemoryLimit; +$memlimit = ini_get( "memory_limit" ); +if( !( empty( $memlimit ) || $memlimit == -1 ) ) { + if( wfParseMemoryLimit( $memlimit ) < wfParseMemoryLimit( $wgMemoryLimit ) ) { + wfDebug( "\n\nRaise PHP's memory limit from $memlimit to $wgMemoryLimit\n" ); + ini_set( "memory_limit", $wgMemoryLimit ); + } +} $wgIP = false; # Load on demand # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor -- 2.20.1