Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -3193,10 +3193,44 @@ |
3194 | 3194 | return $array; |
3195 | 3195 | } |
3196 | 3196 | |
3197 | | -/* Parse PHP's silly format for memory limits */ |
3198 | | -function wfParseMemoryLimit( $memlimit ) { |
3199 | | - $last = strtolower($memlimit[strlen($memlimit)-1]); |
3200 | | - $val = intval( $memlimit ); |
| 3197 | +/** |
| 3198 | + * Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit; |
| 3199 | + * @return Integer value memory was set to. |
| 3200 | + */ |
| 3201 | + |
| 3202 | +function wfMemoryLimit () { |
| 3203 | + global $wgMemoryLimit; |
| 3204 | + $memlimit = wfShorthandToInteger( ini_get( "memory_limit" ) ); |
| 3205 | + $conflimit = wfShorthandToInteger( $wgMemoryLimit ); |
| 3206 | + if( $memlimit != -1 ) { |
| 3207 | + if( $conflimit == -1 ) { |
| 3208 | + wfDebug( "Removing PHP's memory limit\n" ); |
| 3209 | + wfSuppressWarnings(); |
| 3210 | + ini_set( "memory_limit", $conflimit ); |
| 3211 | + wfRestoreWarnings(); |
| 3212 | + return $conflimit; |
| 3213 | + } else { |
| 3214 | + $max = max( $memlimit, $conflimit ); |
| 3215 | + wfDebug( "Raising PHP's memory limit to $max bytes\n" ); |
| 3216 | + wfSuppressWarnings(); |
| 3217 | + ini_set( "memory_limit", $max ); |
| 3218 | + wfRestoreWarnings(); |
| 3219 | + return $max; |
| 3220 | + } |
| 3221 | + } |
| 3222 | + return $memlimit; |
| 3223 | +} |
| 3224 | + |
| 3225 | +/** |
| 3226 | + * Converts shorthand byte notation to integer form |
| 3227 | + * @param $string String |
| 3228 | + * @return Integer |
| 3229 | + */ |
| 3230 | +function wfShorthandToInteger ( $string = '' ) { |
| 3231 | + $string = trim($string); |
| 3232 | + if( empty($string) ) { return -1; } |
| 3233 | + $last = strtolower($string[strlen($string)-1]); |
| 3234 | + $val = intval($string); |
3201 | 3235 | switch($last) { |
3202 | 3236 | case 'g': |
3203 | 3237 | $val *= 1024; |
— | — | @@ -3205,6 +3239,7 @@ |
3206 | 3240 | case 'k': |
3207 | 3241 | $val *= 1024; |
3208 | 3242 | } |
| 3243 | + |
3209 | 3244 | return $val; |
3210 | 3245 | } |
3211 | 3246 | |
— | — | @@ -3233,4 +3268,3 @@ |
3234 | 3269 | $langCode = implode ( '-' , $codeBCP ); |
3235 | 3270 | return $langCode; |
3236 | 3271 | } |
3237 | | - |
Index: trunk/phase3/includes/Setup.php |
— | — | @@ -150,16 +150,7 @@ |
151 | 151 | wfProfileOut( $fname.'-includes' ); |
152 | 152 | wfProfileIn( $fname.'-misc1' ); |
153 | 153 | # Raise the memory limit if it's too low |
154 | | -global $wgMemoryLimit; |
155 | | -$memlimit = ini_get( "memory_limit" ); |
156 | | -if( !( empty( $memlimit ) || $memlimit == -1 ) ) { |
157 | | - if( wfParseMemoryLimit( $memlimit ) < wfParseMemoryLimit( $wgMemoryLimit ) ) { |
158 | | - wfDebug( "\n\nRaise PHP's memory limit from $memlimit to $wgMemoryLimit\n" ); |
159 | | - wfDisableWarnings(); |
160 | | - ini_set( "memory_limit", $wgMemoryLimit ); |
161 | | - wfEnableWarnings(); |
162 | | - } |
163 | | -} |
| 154 | +wfMemoryLimit(); |
164 | 155 | |
165 | 156 | $wgIP = false; # Load on demand |
166 | 157 | # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor |
Index: trunk/phase3/config/index.php |
— | — | @@ -466,18 +466,16 @@ |
467 | 467 | Perl-compatible regular expression functions." ); |
468 | 468 | |
469 | 469 | $memlimit = ini_get( "memory_limit" ); |
470 | | -if( empty( $memlimit ) || $memlimit == -1 ) { |
| 470 | +$newlimit = wfMemoryLimit(); |
| 471 | +global $wgMemoryLimit; |
| 472 | +if( $memlimit == -1 ) { |
471 | 473 | print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n"; |
472 | 474 | } else { |
473 | | - print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". "; |
474 | | - global $wgMemoryLimit; |
475 | | - if( wfParseMemoryLimit( $memlimit ) < wfParseMemoryLimit( $wgMemoryLimit ) ) { |
476 | | - print "Attempting to raise limit to " . htmlspecialchars( $wgMemoryLimit ) . "... "; |
477 | | - if( false === ini_set( "memory_limit", $wgMemoryLimit ) ) { |
478 | | - print "failed.<br /><b>" . htmlspecialchars( $memlimit ) . " seems too low, installation may fail!</b>"; |
479 | | - } else { |
480 | | - print "ok."; |
481 | | - } |
| 475 | + print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ). " bytes. "; |
| 476 | + if( $newlimit >= $wgMemoryLimit ) { |
| 477 | + print "Successfully set limit to " . htmlspecialchars( $newlimit ) . "... "; |
| 478 | + } else { |
| 479 | + print "<b>Failed raising limit, installation may fail.</b>"; |
482 | 480 | } |
483 | 481 | print "</li>\n"; |
484 | 482 | } |