00001 <?php 00002 00003 $optionsWithArgs = array( 'fake-job', 'procs' ); 00004 require( dirname(__FILE__).'/../commandLine.inc' ); 00005 require( dirname(__FILE__).'/gearman.inc' ); 00006 00007 ini_set('memory_limit', '150M' ); 00008 00009 if ( isset( $options['procs'] ) ) { 00010 $procs = $options['procs']; 00011 if ( $procs < 1 || $procs > 1000 ) { 00012 echo "Invalid number of processes, please specify a number between 1 and 1000\n"; 00013 exit( 1 ); 00014 } 00015 $fc = new ForkController( $procs, ForkController::RESTART_ON_ERROR ); 00016 if ( $fc->start() != 'child' ) { 00017 exit( 0 ); 00018 } 00019 } 00020 00021 if ( !$args ) { 00022 $args = array( 'localhost' ); 00023 } 00024 00025 if ( isset( $options['fake-job'] ) ) { 00026 $params = unserialize( $options['fake-job'] ); 00027 MWGearmanJob::runNoSwitch( $params ); 00028 } 00029 00030 $worker = new NonScaryGearmanWorker( $args ); 00031 $worker->addAbility( 'mw_job' ); 00032 $worker->beginWork( 'wfGearmanMonitor' ); 00033 00034 function wfGearmanMonitor( $idle, $lastJob ) { 00035 static $lastSleep = 0; 00036 $interval = 5; 00037 $now = time(); 00038 if ( $now - $lastSleep >= $interval ) { 00039 wfWaitForSlaves( $interval ); 00040 $lastSleep = $now; 00041 } 00042 return false; 00043 }