note 117669 added to gearmanclient.addtask
| From: | liv_romania at yahoo dot com | Date: | Sun, 19 Jul 2015 12:08:08 +0000 |
| Subject: | note 117669 added to gearmanclient.addtask | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203135@lists.php.net to get a copy of this message | ||
On PHP 5.5 you can use the following code for passing context by reference and avoid "Call-time
pass-by-reference has been removed":
<?php
$client = new GearmanClient();
$client->addServer();
# Set a function to be called when the work is complete
$client->setCompleteCallback("reverse_complete");
# Use StdClass instead of array
$results = new StdClass();
$results->value = array();
# Add some tasks for a placeholder of where to put the results
$client->addTask("reverse", "Hello World!", $results, "t1");
$client->addTask("reverse", "!dlroW olleH", $results, "t2");
$client->runTasks();
# The results should now be filled in from the callbacks
foreach ($results->value as $id => $result) {
echo $id . ": " . $result['handle'] . ", " .
$result['data'] . "\n";
}
function reverse_complete(GearmanTask $task, StdClass $results)
{
$results->value[$task->unique()] = array(
"handle" => $task->jobHandle(),
"data" => $task->data()
);
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 46.102.29.170
----
Manual Page -- http://php.net/manual/en/gearmanclient.addtask.php
Edit -- https://master.php.net/note/edit/117669
Del: integrated -- https://master.php.net/note/delete/117669/integrated
Del: useless -- https://master.php.net/note/delete/117669/useless
Del: bad code -- https://master.php.net/note/delete/117669/bad+code
Del: spam -- https://master.php.net/note/delete/117669/spam
Del: non-english -- https://master.php.net/note/delete/117669/non-english
Del: in docs -- https://master.php.net/note/delete/117669/in+docs
Del: other reasons-- https://master.php.net/note/delete/117669
Reject -- https://master.php.net/note/reject/117669
Search -- https://master.php.net/manage/user-notes.php