Service/GearmanExecute.php
private function callJob(Array $worker, array $options = array(), \GearmanWorker $gearmanWorker = null)
    {
        if(is_null($gearmanWorker)) {
            $gearmanWorker = new \GearmanWorker;
        }

        if (isset($worker['job'])) {

            $jobs = array($worker['job']);
            $iterations = $worker['job']['iterations'];
            $minimumExecutionTime = $worker['job']['minimumExecutionTime'];
            $timeout = $worker['job']['timeout'];
            $successes = $this->addServers($gearmanWorker, $worker['job']['servers']);

        } else {

            $jobs = $worker['jobs'];
            $iterations = $worker['iterations'];
            $minimumExecutionTime = $worker['minimumExecutionTime'];
            $timeout = $worker['timeout'];
            $successes = $this->addServers($gearmanWorker, $worker['servers']);
        }

        $options = $this->executeOptionsResolver->resolve($options);

        $iterations           = $options['iterations']             ?: $iterations;
        $minimumExecutionTime = $options['minimum_execution_time'] ?: $minimumExecutionTime;
        $timeout              = $options['timeout']                ?: $timeout;

        if (count($successes) < 1) {
            if ($minimumExecutionTime > 0) {
                sleep($minimumExecutionTime);
            }
            throw new ServerConnectionException('Worker was unable to connect to any server.');
        }

        $objInstance = $this->createJob($worker);

        /**
         * Start the timer before running the worker.
         */
        $time = time();
        $this->runJob($gearmanWorker, $objInstance, $jobs, $iterations, $timeout);

        /**
         * If there is a minimum expected duration, wait out the remaining period if there is any.
         */
        if ($minimumExecutionTime > 0) {
            $now = time();
            $remaining = $minimumExecutionTime - ($now - $time);

            if ($remaining > 0) {
                sleep($remaining);
            }
        }

        return $this;
    }
private function callJob(Array $worker, array $options = array(), \GearmanWorker $gearmanWorker = null)
    {
        if(is_null($gearmanWorker)) {
            $gearmanWorker = new \GearmanWorker;
        }

        if (isset($worker['job'])) {

            $jobs = array($worker['job']);
            $iterations = $worker['job']['iterations'];
            $minimumExecutionTime = $worker['job']['minimumExecutionTime'];
            $timeout = $worker['job']['timeout'];
            $successes = $this->addServers($gearmanWorker, $worker['job']['servers']);

        } else {

            $jobs = $worker['jobs'];
            $iterations = $worker['iterations'];
            $minimumExecutionTime = $worker['minimumExecutionTime'];
            $timeout = $worker['timeout'];
            $successes = $this->addServers($gearmanWorker, $worker['servers']);
        }

        $options = $this->executeOptionsResolver->resolve($options);

        $iterations           = $options['iterations']             ?: $iterations;
        $minimumExecutionTime = $options['minimum_execution_time'] ?: $minimumExecutionTime;
        $timeout              = $options['timeout']                ?: $timeout;

        if (count($successes) < 1) {
            if ($minimumExecutionTime > 0) {
                sleep($minimumExecutionTime);
            }
            throw new ServerConnectionException('Worker was unable to connect to any server.');
        }

        $objInstance = $this->createJob($worker);

        /**
         * Start the timer before running the worker.
         */
        $time = time();
        $this->runJob($gearmanWorker, $objInstance, $jobs, $iterations, $timeout);

        /**
         * If there is a minimum expected duration, wait out the remaining period if there is any.
         */
        if ($minimumExecutionTime > 0) {
            $now = time();
            $remaining = $minimumExecutionTime - ($now - $time);

            if ($remaining > 0) {
                sleep($remaining);
            }
        }

        return $this;
    }
private function callJob ( Array $ worker , array $ options = array ( ) , \ GearmanWorker $ gearmanWorker = null ) { if ( is_null ( $ gearmanWorker ) ) { $ gearmanWorker = new \ GearmanWorker ; } if ( isset ( $ worker [ 'job' ] ) ) { $ jobs = array ( $ worker [ 'job' ] ) ; $ iterations = $ worker [ 'job' ] [ 'iterations' ] ; $ minimumExecutionTime = $ worker [ 'job' ] [ 'minimumExecutionTime' ] ; $ timeout = $ worker [ 'job' ] [ 'timeout' ] ; $ successes = $ this -> addServers ( $ gearmanWorker , $ worker [ 'job' ] [ 'servers' ] ) ; } else { $ jobs = $ worker [ 'jobs' ] ; $ iterations = $ worker [ 'iterations' ] ; $ minimumExecutionTime = $ worker [ 'minimumExecutionTime' ] ; $ timeout = $ worker [ 'timeout' ] ; $ successes = $ this -> addServers ( $ gearmanWorker , $ worker [ 'servers' ] ) ; } $ options = $ this -> executeOptionsResolver -> resolve ( $ options ) ; $ iterations = $ options [ 'iterations' ] ? : $ iterations ; $ minimumExecutionTime = $ options [ 'minimum_execution_time' ] ? : $ minimumExecutionTime ; $ timeout = $ options [ 'timeout' ] ? : $ timeout ; if ( count ( $ successes ) < 1 ) { if ( $ minimumExecutionTime > 0 ) { sleep ( $ minimumExecutionTime ) ; } throw new ServerConnectionException ( 'Worker was unable to connect to any server.' ) ; } $ objInstance = $ this -> createJob ( $ worker ) ; /**
         * Start the timer before running the worker.
         */ $ time = time ( ) ; $ this -> runJob ( $ gearmanWorker , $ objInstance , $ jobs , $ iterations , $ timeout ) ; /**
         * If there is a minimum expected duration, wait out the remaining period if there is any.
         */ if ( $ minimumExecutionTime > 0 ) { $ now = time ( ) ; $ remaining = $ minimumExecutionTime - ( $ now - $ time ) ; if ( $ remaining > 0 ) { sleep ( $ remaining ) ; } } return $ this ; }
Given a worker, execute GearmanWorker function defined by job.

@param array $worker Worker definition
@param array $options Array of options passed to the callback
@param \GearmanWorker $gearmanWorker Worker instance to use

@throws ServerConnectionException if a connection to a server was not possible.

@return GearmanExecute self Object
Given a worker execute GearmanWorker function defined by job .