Perl-compatible regular expression functions." );
$memlimit = ini_get( "memory_limit" );
-if( empty( $memlimit ) || $memlimit == -1 ) {
+$newlimit = wfMemoryLimit();
+global $wgMemoryLimit;
+if( $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 ) . ". ";
- 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 {
- print "ok.";
- }
+ print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ). " bytes. ";
+ if( $newlimit >= $wgMemoryLimit ) {
+ print "Successfully set limit to " . htmlspecialchars( $newlimit ) . "... ";
+ } else {
+ print "<b>Failed raising limit, installation may fail.</b>";
}
print "</li>\n";
}
return $array;
}
-/* Parse PHP's silly format for memory limits */
-function wfParseMemoryLimit( $memlimit ) {
- $last = strtolower($memlimit[strlen($memlimit)-1]);
- $val = intval( $memlimit );
+/**
+ * Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit;
+ * @return Integer value memory was set to.
+ */
+
+function wfMemoryLimit () {
+ global $wgMemoryLimit;
+ $memlimit = wfShorthandToInteger( ini_get( "memory_limit" ) );
+ $conflimit = wfShorthandToInteger( $wgMemoryLimit );
+ if( $memlimit != -1 ) {
+ if( $conflimit == -1 ) {
+ wfDebug( "Removing PHP's memory limit\n" );
+ wfSuppressWarnings();
+ ini_set( "memory_limit", $conflimit );
+ wfRestoreWarnings();
+ return $conflimit;
+ } else {
+ $max = max( $memlimit, $conflimit );
+ wfDebug( "Raising PHP's memory limit to $max bytes\n" );
+ wfSuppressWarnings();
+ ini_set( "memory_limit", $max );
+ wfRestoreWarnings();
+ return $max;
+ }
+ }
+ return $memlimit;
+}
+
+/**
+ * Converts shorthand byte notation to integer form
+ * @param $string String
+ * @return Integer
+ */
+function wfShorthandToInteger ( $string = '' ) {
+ $string = trim($string);
+ if( empty($string) ) { return -1; }
+ $last = strtolower($string[strlen($string)-1]);
+ $val = intval($string);
switch($last) {
case 'g':
$val *= 1024;
case 'k':
$val *= 1024;
}
+
return $val;
}
$langCode = implode ( '-' , $codeBCP );
return $langCode;
}
-
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" );
- wfDisableWarnings();
- ini_set( "memory_limit", $wgMemoryLimit );
- wfEnableWarnings();
- }
-}
+wfMemoryLimit();
$wgIP = false; # Load on demand
# Can't stub this one, it sets up $_GET and $_REQUEST in its constructor