r74849 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74848‎ | r74849 | r74850 >
Date:18:33, 16 October 2010
Author:maxsem
Status:resolved (Comments)
Tags:
Comment:
Follow-up r74841:
* Moved command line parsing up so that the first use of --memory-limit actually works
* Now limit of 0 means that we shouldn't attempt to change it at all
Modified paths:
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/Maintenance.php
@@ -351,7 +351,7 @@
352352 $this->addOption( 'conf', 'Location of LocalSettings.php, if not default', false, true );
353353 $this->addOption( 'wiki', 'For specifying the wiki ID', false, true );
354354 $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' );
356356 // If we support a DB, show the options
357357 if ( $this->getDbType() > 0 ) {
358358 $this->addOption( 'dbuser', 'The DB user to use for this script', false, true );
@@ -431,9 +431,12 @@
432432 // command-line mode is on, regardless of PHP version.
433433 }
434434
 435+ $this->loadParamsAndArgs();
 436+ $this->maybeHelp();
 437+
435438 # Set the memory limit
436439 # Note we need to set it again later in cache LocalSettings changed it
437 - ini_set( 'memory_limit', $this->memoryLimit() );
 440+ $this->adjustMemoryLimit();
438441
439442 # Set max execution time to 0 (no limit). PHP.net says that
440443 # "When running PHP from the command line the default setting is 0."
@@ -454,8 +457,6 @@
455458 # Turn off output buffering if it's on
456459 @ob_end_flush();
457460
458 - $this->loadParamsAndArgs();
459 - $this->maybeHelp();
460461 $this->validateParamsAndArgs();
461462 }
462463
@@ -472,6 +473,15 @@
473474 }
474475
475476 /**
 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+ /**
476486 * Clear all params and arguments.
477487 */
478488 public function clearParamsAndArgs() {
@@ -706,7 +716,7 @@
707717
708718 $wgShowSQLErrors = true;
709719 @set_time_limit( 0 );
710 - ini_set( 'memory_limit', $this->memoryLimit() );
 720+ $this->adjustMemoryLimit();
711721
712722 $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors
713723 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r74884Fix for r74849: use 'default' instead of 0 to indicate no memory-limit change.maxsem08:59, 17 October 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r74841Allow overriding default memory limits in maintenance scripts (which is usual...demon17:30, 16 October 2010

Comments

#Comment by Brion VIBBER (talk | contribs)   22:51, 16 October 2010

It seems odd to me that actively passing 0 leaves the existing setting from php.ini; I'd expect that to disable the memory limit, as -1 does...

It looks like PHP's own behavior is that any non-negative number less than 262,144 (256kb) gets rounded up to 256kb as the smallest possible limit, including setting it to 0.

Maybe 'default' rather than 0 here?

#Comment by MaxSem (talk | contribs)   09:08, 17 October 2010

Done.

Status & tagging log