switchWiki( $params['wiki'], $params ); } self::runNoSwitch( $params ); } static function runNoSwitch( $params ) { echo implode( ' ', $params ) . "\n"; $title = Title::newFromText( $params['title'] ); $mwJob = Job::factory( $params['command'], $title, $params['params'] ); return $mwJob->run(); } } class NonScaryGearmanWorker extends Net_Gearman_Worker { /** * Copied from Net_Gearman_Worker but with the scary "run any PHP file in * the filesystem" feature removed. */ protected function doWork($socket) { Net_Gearman_Connection::send($socket, 'grab_job'); $resp = array('function' => 'noop'); while (count($resp) && $resp['function'] == 'noop') { $resp = Net_Gearman_Connection::blockingRead($socket); } if (in_array($resp['function'], array('noop', 'no_job'))) { return false; } if ($resp['function'] != 'job_assign') { throw new Net_Gearman_Exception('Holy Cow! What are you doing?!'); } $name = $resp['data']['func']; $handle = $resp['data']['handle']; $arg = array(); if (isset($resp['data']['arg']) && Net_Gearman_Connection::stringLength($resp['data']['arg'])) { $arg = json_decode($resp['data']['arg'], true); } ### START MW DIFFERENT BIT if ( $name != 'mw_job' ) { throw new Net_Gearman_Job_Exception('Invalid function'); } $job = new MWGearmanJob($socket, $handle); ### END MW DIFFERENT BIT try { $this->start($handle, $name, $arg); $res = $job->run($arg); if (!is_array($res)) { $res = array('result' => $res); } $job->complete($res); $this->complete($handle, $name, $res); } catch (Net_Gearman_Job_Exception $e) { $job->fail(); $this->fail($handle, $name, $e); } // Force the job's destructor to run $job = null; return true; } }