* Refactored the forking code from runJobs.php to a new class called ForkController...
[lhc/web/wiklou.git] / maintenance / gearman / gearmanWorker.php
1 <?php
2
3 $optionsWithArgs = array( 'fake-job', 'procs' );
4 require( dirname(__FILE__).'/../commandLine.inc' );
5 require( dirname(__FILE__).'/gearman.inc' );
6
7 if ( isset( $options['procs'] ) ) {
8 $procs = $options['procs'];
9 if ( $procs < 1 || $procs > 1000 ) {
10 echo "Invalid number of processes, please specify a number between 1 and 1000\n";
11 exit( 1 );
12 }
13 $fc = new ForkController;
14 if ( $fc->forkWorkers( $procs ) == 'parent' ) {
15 $fc->runParent();
16 exit( 0 );
17 }
18 }
19
20 if ( !$args ) {
21 $args = array( 'localhost' );
22 }
23
24 if ( isset( $options['fake-job'] ) ) {
25 $params = unserialize( $options['fake-job'] );
26 MWGearmanJob::runNoSwitch( $params );
27 }
28
29 $worker = new NonScaryGearmanWorker( $args );
30 $worker->addAbility( 'mw_job' );
31 $worker->beginWork();
32