Merge and clean up memory_limit hacks from wmf-deployment r53208.
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 14 Sep 2009 22:10:10 +0000 (22:10 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 14 Sep 2009 22:10:10 +0000 (22:10 +0000)
Added a memoryLimit() method on Maintenance class which allows scripts to override the memory limit; normally we disable the limit but sometimes you actually want to set one to avoid eating up RAM on the machine if something goes awry.

maintenance/Maintenance.php
maintenance/gearman/gearmanWorker.php
maintenance/rebuildLocalisationCache.php
maintenance/runJobs.php

index 88af7ab..452acf4 100644 (file)
@@ -333,7 +333,7 @@ abstract class Maintenance {
                }
 
                # Set the memory limit
-               ini_set( 'memory_limit', -1 );
+               ini_set( 'memory_limit', $this->memoryLimit() );
 
                # Set max execution time to 0 (no limit). PHP.net says that
                # "When running PHP from the command line the default setting is 0."
@@ -362,6 +362,15 @@ abstract class Maintenance {
                $this->maybeHelp();
                $this->validateParamsAndArgs();
        }
+       
+       /**
+        * Normally we disable the memory_limit when running admin scripts.
+        * Some scripts may wish to actually set a limit, however, to avoid
+        * blowing up unexpectedly.
+        */
+       public function memoryLimit() {
+               return -1;
+       }
 
        /**
         * Clear all params and arguments.
index 0b26ff9..d6f3949 100644 (file)
@@ -4,6 +4,8 @@ $optionsWithArgs = array( 'fake-job', 'procs' );
 require( dirname(__FILE__).'/../commandLine.inc' );
 require( dirname(__FILE__).'/gearman.inc' );
 
+ini_set('memory_limit', '150M' );
+
 if ( isset( $options['procs'] ) ) {
        $procs = $options['procs'];
        if ( $procs < 1 || $procs > 1000 ) {
index d1cff3c..1c51741 100644 (file)
@@ -37,12 +37,14 @@ class RebuildLocalisationCache extends Maintenance {
                $this->addOption( 'force', 'Rebuild all files, even ones not out of date' );
                $this->addOption( 'threads', 'Fork more than one thread', false, true );
        }
+       
+       public function memoryLimit() {
+               return '200M';
+       }
 
        public function execute() {
                global $wgLocalisationCacheConf;
 
-               ini_set( 'memory_limit', '200M' );
-
                $force = $this->hasOption('force');
                $threads = $this->getOption( 'threads', 1 );
                if( $threads < 1 || $threads != intval( $threads ) ) {
index acadcf6..70228ff 100644 (file)
@@ -36,6 +36,11 @@ class RunJobs extends Maintenance {
                $this->addOption( 'procs', 'Number of processes to use', false, true );
                $wgUseNormalUser = true;
        }
+       
+       public function memoryLimit() {
+               // Don't eat all memory on the machine if we get a bad job.
+               return "150M";
+       }
 
        public function execute() {
                global $wgTitle;