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

Switch to another languags Deutsch aktuelle Sprache Englisch

PHP Manual


(PECL gearman >= 0.5.0)

GearmanClient::addTaskAdd a task to be run in parallel


public GearmanTask GearmanClient::addTask ( string $function_name , string $workload [, mixed &$context [, string $unique ]] )

Adds a task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks() to perform the work. Note that enough workers need to be available for the tasks to all run in parallel.



A registered function the worker is to execute


Serialized data to be processed


Application context to associate with a task


A unique ID used to identify a particular task

Return Values

A GearmanTask object or FALSE if the task could not be added.


Example #1 Basic submission of two tasks


# Create our gearman client
$gmclient= new GearmanClient(); 

# add the default job server

# add a task to perform the "reverse" function on the string "Hello World!"
$gmclient->addTask("reverse""Hello World!"null"1"); 

# add another task to perform the "reverse" function on the string "!dlroW olleH"
$gmclient->addTask("reverse""!dlroW olleH"null"2"); 

# set a function to be called when the work is complete

# run the tasks


"COMPLETE: " $task->unique() . ", " $task->data() . "\n"


The above example will output something similar to:

COMPLETE: 2, Hello World!
COMPLETE: 1, !dlroW olleH

Example #2 Basic submission of two tasks with passing application context


= new GearmanClient();

# Add some tasks for a placeholder of where to put the results
$results = array();
$client->addTask("reverse""Hello World!", &$results"t1");
$client->addTask("reverse""!dlroW olleH", &$results"t2");


# The results should now be filled in from the callbacks
foreach ($results as $id => $result)
$id ": " $result['handle'] . ", " $result['data'] . "\n";

$results[$task->unique()] = array("handle"=>$task->jobHandle(), "data"=>$task->data());


The above example will output something similar to:

t2:, Hello World!
t1: H:foo:22, !dlroW olleH

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