Index: trunk/phase3/maintenance/Maintenance.php |
— | — | @@ -351,7 +351,7 @@ |
352 | 352 | $this->addOption( 'conf', 'Location of LocalSettings.php, if not default', false, true ); |
353 | 353 | $this->addOption( 'wiki', 'For specifying the wiki ID', false, true ); |
354 | 354 | $this->addOption( 'globals', 'Output globals at the end of processing for debugging' ); |
355 | | - $this->addOption( 'memory-limit', 'Set a specific memory limit for the script' ); |
| 355 | + $this->addOption( 'memory-limit', 'Set a specific memory limit for the script, -1 for no limit or 0 to avoid changing it' ); |
356 | 356 | // If we support a DB, show the options |
357 | 357 | if ( $this->getDbType() > 0 ) { |
358 | 358 | $this->addOption( 'dbuser', 'The DB user to use for this script', false, true ); |
— | — | @@ -431,9 +431,12 @@ |
432 | 432 | // command-line mode is on, regardless of PHP version. |
433 | 433 | } |
434 | 434 | |
| 435 | + $this->loadParamsAndArgs(); |
| 436 | + $this->maybeHelp(); |
| 437 | + |
435 | 438 | # Set the memory limit |
436 | 439 | # Note we need to set it again later in cache LocalSettings changed it |
437 | | - ini_set( 'memory_limit', $this->memoryLimit() ); |
| 440 | + $this->adjustMemoryLimit(); |
438 | 441 | |
439 | 442 | # Set max execution time to 0 (no limit). PHP.net says that |
440 | 443 | # "When running PHP from the command line the default setting is 0." |
— | — | @@ -454,8 +457,6 @@ |
455 | 458 | # Turn off output buffering if it's on |
456 | 459 | @ob_end_flush(); |
457 | 460 | |
458 | | - $this->loadParamsAndArgs(); |
459 | | - $this->maybeHelp(); |
460 | 461 | $this->validateParamsAndArgs(); |
461 | 462 | } |
462 | 463 | |
— | — | @@ -472,6 +473,15 @@ |
473 | 474 | } |
474 | 475 | |
475 | 476 | /** |
| 477 | + * Adjusts PHP's memory limit to better suit our needs, if needed. |
| 478 | + */ |
| 479 | + protected function adjustMemoryLimit() { |
| 480 | + if ( $this->memoryLimit() != 0 ) { |
| 481 | + ini_set( 'memory_limit', $this->memoryLimit() ); |
| 482 | + } |
| 483 | + } |
| 484 | + |
| 485 | + /** |
476 | 486 | * Clear all params and arguments. |
477 | 487 | */ |
478 | 488 | public function clearParamsAndArgs() { |
— | — | @@ -706,7 +716,7 @@ |
707 | 717 | |
708 | 718 | $wgShowSQLErrors = true; |
709 | 719 | @set_time_limit( 0 ); |
710 | | - ini_set( 'memory_limit', $this->memoryLimit() ); |
| 720 | + $this->adjustMemoryLimit(); |
711 | 721 | |
712 | 722 | $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors |
713 | 723 | } |