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