GearmanClient::do
GearmanClient::doHigh
GearmanClient
PHP Manual

# GearmanClient::doBackground

(PECL gearman >= 0.5.0)

GearmanClient::doBackground — Run a task in the background

### Description

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.

### Liste de paramètres

`function_name`

  Une fonction enregistrée que le travailleur va exécuter

`workload`

  Données linéarisées à analyser

`unique`

  Un identifiant unique utilisé pour identifier une tâche particulière

### Valeurs de retour

The job handle for the submitted task.

### Exemples

Exemple #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.

`<?php
/* create our object */
$gmclient= new GearmanClient();
/* add the default server */
$gmclient->addServer();
/* run reverse client */
$job_handle = $gmclient->doBackground("reverse", "this is a test");
if ($gmclient->returnCode() != GEARMAN_SUCCESS)
{
echo "bad return code\n";
exit;
}
$done = false;
do
{
sleep(3);
$stat = $gmclient->jobStatus($job_handle);
if (!$stat[0]) // the job is known so it is not done
$done = true;
echo "Running: " . ($stat[1] ? "true" : "false") . ", numerator: " . $stat[2] . ", denomintor: " . $stat[3] . "\n";
}
while(!$done);
echo "done!\n";
?>`

L'exemple ci-dessus va afficher quelque chose de similaire à :

    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
    done!

### Voir aussi

- GearmanClient::do - Run a single task and return a result
- GearmanClient::doHigh - Run a single high priority task
- GearmanClient::doLow - Run a single low priority task
- GearmanClient::doHighBackground - Run a high priority task in the background
- GearmanClient::doLowBackground - Run a low priority task in the background

GearmanClient::do
GearmanClient::doHigh
GearmanClient
PHP Manual