From 7764794ddbf85e75e8352a98291792013fce52f0 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 14 Sep 2009 22:10:10 +0000 Subject: [PATCH] Merge and clean up memory_limit hacks from wmf-deployment r53208. 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 | 11 ++++++++++- maintenance/gearman/gearmanWorker.php | 2 ++ maintenance/rebuildLocalisationCache.php | 6 ++++-- maintenance/runJobs.php | 5 +++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 88af7ab25c..452acf4772 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -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. diff --git a/maintenance/gearman/gearmanWorker.php b/maintenance/gearman/gearmanWorker.php index 0b26ff9f17..d6f3949fe4 100644 --- a/maintenance/gearman/gearmanWorker.php +++ b/maintenance/gearman/gearmanWorker.php @@ -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 ) { diff --git a/maintenance/rebuildLocalisationCache.php b/maintenance/rebuildLocalisationCache.php index d1cff3c2d3..1c51741510 100644 --- a/maintenance/rebuildLocalisationCache.php +++ b/maintenance/rebuildLocalisationCache.php @@ -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 ) ) { diff --git a/maintenance/runJobs.php b/maintenance/runJobs.php index acadcf67c8..70228ffbaf 100644 --- a/maintenance/runJobs.php +++ b/maintenance/runJobs.php @@ -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; -- 2.20.1