src/JobAwareTrait.php
public function execute($name, $workload, $background = true, $priority = Gearman::PRIORITY_NORMAL)
    {
        $func = 'do';
        switch ($priority) {
            case Gearman::PRIORITY_LOW:
                $func .= 'Low';
                break;
            case Gearman::PRIORITY_HIGH:
                $func .= 'High';
                break;
            case Gearman::PRIORITY_NORMAL:
                if (!$background) {
                    $func .= 'Normal';
                }
                break;
        }
        $func .= ($background) ? 'Background' : '';

        if (is_array($workload) || is_object($workload)) {
            $workload = serialize($workload);
        }

        $response = $this->gearmanClient()->{$func}($name, $workload);

        DebugJob::add($name, $workload, $background, $priority);

        if ($background) {
            return $response;
        }

        $serializedResponse = unserialize($response);

        if ($serializedResponse !== false) {
            $response = $serializedResponse;
        }

        return $response;
    }
public function execute($name, $workload, $background = true, $priority = Gearman::PRIORITY_NORMAL)
    {
        $func = 'do';
        switch ($priority) {
            case Gearman::PRIORITY_LOW:
                $func .= 'Low';
                break;
            case Gearman::PRIORITY_HIGH:
                $func .= 'High';
                break;
            case Gearman::PRIORITY_NORMAL:
                if (!$background) {
                    $func .= 'Normal';
                }
                break;
        }
        $func .= ($background) ? 'Background' : '';

        if (is_array($workload) || is_object($workload)) {
            $workload = serialize($workload);
        }

        $response = $this->gearmanClient()->{$func}($name, $workload);

        DebugJob::add($name, $workload, $background, $priority);

        if ($background) {
            return $response;
        }

        $serializedResponse = unserialize($response);

        if ($serializedResponse !== false) {
            $response = $serializedResponse;
        }

        return $response;
    }
public function execute ( $ name , $ workload , $ background = true , $ priority = Gearman :: PRIORITY_NORMAL ) { $ func = 'do' ; switch ( $ priority ) { case Gearman :: PRIORITY_LOW : $ func .= 'Low' ; break ; case Gearman :: PRIORITY_HIGH : $ func .= 'High' ; break ; case Gearman :: PRIORITY_NORMAL : if ( ! $ background ) { $ func .= 'Normal' ; } break ; } $ func .= ( $ background ) ? 'Background' : '' ; if ( is_array ( $ workload ) || is_object ( $ workload ) ) { $ workload = serialize ( $ workload ) ; } $ response = $ this -> gearmanClient ( ) -> { $ func } ( $ name , $ workload ) ; DebugJob :: add ( $ name , $ workload , $ background , $ priority ) ; if ( $ background ) { return $ response ; } $ serializedResponse = unserialize ( $ response ) ; if ( $ serializedResponse !== false ) { $ response = $ serializedResponse ; } return $ response ; }
Execute a job by sending it to the
Gearman server using the GearmanClient.

Example for a background job with normal priority:
$this->execute('sleep', ['seconds' => 60]);

Example for a background job with HIGH priority:
$this->execute('sleep', ['seconds' => 60], true, Gearman::PRIORITY_HIGH);

Example for a normal job with HIGH priority:
$this->execute('sleep', ['seconds' => 60], false, Gearman::PRIORITY_HIGH);

@param string $name Name of the job to execute
@param mixed  $workload Any type of workload is supported (as long as it's serializable)
@param bool   $background If it's a background job
@param int    $priority A priority level from Gearman::PRIORTIY_*
@return mixed The response from the job or the job id in case of a background job
Execute a job by sending it to the Gearman server using the GearmanClient .