|
GearmanClient::addTaskBackgroundAdd a background task to be run in parallel Description
public GearmanTask GearmanClient::addTaskBackground
( string
$function_name
, string $workload
[, mixed &$context
[, string $unique
]] )Adds a background 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. Parameters
Return Values
A GearmanTask object or Examples
Example #1 Two tasks, one background and one not This example illustrates the difference between running a background task and a normal task. The client adds two tasks to execute the same function, but one is added with addTaskBackground. A callback is set so that progress of the job can be tracked. A simple worker with an artificial delay reports on the job progress and the client picks this up through the callback. Two workers are run for this example. Note that the background task does not show in the client output.
<?php
<?php Worker output for two workers running: Received job: H:foo.local:65 Workload: !dlroW olleH (12) 1/12 complete Received job: H:foo.local:66 Workload: Hello World! (12) 1/12 complete 2/12 complete 2/12 complete 3/12 complete 3/12 complete 4/12 complete 4/12 complete 5/12 complete 5/12 complete 6/12 complete 6/12 complete 7/12 complete 7/12 complete 8/12 complete 8/12 complete 9/12 complete 9/12 complete 10/12 complete 10/12 complete 11/12 complete 11/12 complete 12/12 complete 12/12 complete Result: !dlroW olleH Result: Hello World! Client output: STATUS: 1, H:foo.local:66 - 1/12 STATUS: 1, H:foo.local:66 - 2/12 STATUS: 1, H:foo.local:66 - 3/12 STATUS: 1, H:foo.local:66 - 4/12 STATUS: 1, H:foo.local:66 - 5/12 STATUS: 1, H:foo.local:66 - 6/12 STATUS: 1, H:foo.local:66 - 7/12 STATUS: 1, H:foo.local:66 - 8/12 STATUS: 1, H:foo.local:66 - 9/12 STATUS: 1, H:foo.local:66 - 10/12 STATUS: 1, H:foo.local:66 - 11/12 STATUS: 1, H:foo.local:66 - 12/12 COMPLETE: 1, !dlroW olleH DONE See Also
|