IMPRESS dotted_line CONTACT dotted_line search dotted_line Kontakt dotted_line sitemap dotted_line print
97 PHP-Resource users online

Switch to another languags Deutsch aktuelle Sprache Englisch

PHP Manual


(PECL gearman >= 0.5.0)

GearmanClient::doBackgroundRun a task in the background


public string GearmanClient::doBackground ( string $function_name , string $workload [, string $unique ] )

Runs a task in the background, returning a job handle which can be used to get the status of the running task.



A registered function the worker is to execute


Serialized data to be processed


A unique ID used to identify a particular task

Return Values

The job handle for the submitted task.


Example #1 Submit and monitor a background job

The worker in this example has an artificial delay introduced to mimic a long running job. The client script periodically checks the status of the running job.


/* create our object */
$gmclient= new GearmanClient();

/* add the default server */

/* run reverse client */
$job_handle $gmclient->doBackground("reverse""this is a test");

if (
$gmclient->returnCode() != GEARMAN_SUCCESS)
"bad return code\n";

$done false;
$stat $gmclient->jobStatus($job_handle);
   if (!
$stat[0]) // the job is known so it is not done
$done true;
"Running: " . ($stat[1] ? "true" "false") . ", numerator: " $stat[2] . ", denomintor: " $stat[3] . "\n";



The above example will output something similar to:

Running: true, numerator: 3, denomintor: 14
Running: true, numerator: 6, denomintor: 14
Running: true, numerator: 9, denomintor: 14
Running: true, numerator: 12, denomintor: 14
Running: false, numerator: 0, denomintor: 0

See Also

Comments to the PHP manual
Write new comment


New Tutorial entries

Migration einer PHP 5 App auf PHP 7

Dieses PHP 7 Tutorial zeigt dir, wie du dein PHP5 Script auf PHP7 umstellst.

Berni | Category: PHP
PHP 7 Virtual Machine

Dieser Artikel zielt darauf ab, einen Überblick über die Zend Virtual Machine, wie es in PHP 7 gefunden wird.

Berni | Category: PHP
plotting masters - a professional guide - Teil II

Grafische Interpolation und Bestapproximation von numerischen Wertepaaren: Wir wollen Punkte auf einer Zeichenebene über verschiedene Verfahren miteinander verbinden.

EVAMasters | Category: PHP