php-gearman
php-gearman copied to clipboard
How do you wait for results when using doHighBackground?
Hi,
I'm using Gearman to do some processing in background, but I need the results when finished. From documentation of PHP for Gearman, and your implementation I see that there is a part where I should wait for results while($worker->work()) {}
. However I'm not able to get the results. This is what I have:
$r = [];
$r['status'] = false;
$tmp = [];
$chunkedData = array_chunk($originalData, (int)(ceil(count($originalData) / 5)));
for($i = 0; $i < count($chunkedData ); $i++) {
$r = Gearman::doHighBackground('parse_data', ['data' => $chunkedData [$i]]);
// how to wait for $r['data'] ?
array_push($tmp, $r['data']);
}
and my Laravel command handle()
method :
public function handle()
{
Gearman::runWorker('parse_data', function(GearmanJob $job) {
$this->line('<fg=yellow;>Started parsing data..</>');
$data = Gearman::deserializeWorkload($job->workload());
$data= $data['data'];
$res = $this->processData($data);
$data = array_values(array_map("unserialize",
array_unique(array_map("serialize", $res))));
$this->line('<fg=yellow;>Parsing finished.</>');
return Gearman::serializeWorkload(['status' => true, 'data' => $data]);
});
}
Thank you!