php8.5
Home/ Manual/ gearman / gearmanworker/ GearmanWorker::work

GearmanWorker::work

PHP function Edit on GitHub ✎

(PECL gearman >= 0.5.0)

Wait for and perform jobs

Description

GearmanWorker::work(): bool

Waits for a job to be assigned and then calls the appropriate callback function. Issues an E_WARNING with the last Gearman error if the return code is not one of GEARMAN_SUCCESS, GEARMAN_IO_WAIT, or GEARMAN_WORK_FAIL.

Parameters Parameters

Return Values

Success

Examples

GearmanWorker::work example

php
<?php

# create the worker
$worker = new GearmanWorker();

# add the default job server (localhost)
$worker->addServer();

# add the reverse function
$worker->addFunction("reverse", "my_reverse_function");

# start te worker listening for job submissions
while ($worker->work());

function my_reverse_function($job)
{
  return strrev($job->workload());
}

?>

See Also

  • GearmanWorker::addFunction

Source: reference/gearman/gearmanworker/work.xml · from the official PHP manual (php/doc-en)