(bug 16084) Default memory limit should be increased
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 4 Aug 2009 02:47:39 +0000 (02:47 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 4 Aug 2009 02:47:39 +0000 (02:47 +0000)
RELEASE-NOTES
config/index.php
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/Setup.php

index 5179221..cfff529 100644 (file)
@@ -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 ==
 
index 598e356..cb83d12 100644 (file)
@@ -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 "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
 } else {
        print "<li>PHP's <tt>memory_limit</tt> 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.<br /><b>" . htmlspecialchars( $memlimit ) . " seems too low, installation may fail!</b>";
                } 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\" );
index d16d97a..d7a0e3e 100644 (file)
@@ -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";
+
index 3fc61e6..2dba0d0 100644 (file)
@@ -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.
index 0021f5f..462e201 100644 (file)
@@ -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