Skip to content

Instantly share code, notes, and snippets.

@omerucel
Last active August 29, 2015 14:02
Show Gist options
  • Save omerucel/97a09b185894281a12b7 to your computer and use it in GitHub Desktop.
Save omerucel/97a09b185894281a12b7 to your computer and use it in GitHub Desktop.
<?php
$jobHandles = [];
foreach ($jobs as $job) {
$jobHandles[] = $this->getGearmanClient()->doBackground('work', json_encode($job));
}
do {
$jobHandleCount = count($jobHandles);
if ($jobHandleCount == 0) {
break;
}
$removedIndex = [];
for ($index = 0; $index < $jobHandleCount; $index++) {
$stat = $this->getGearmanClient()->jobStatus($jobHandles[$index]);
if (!$stat[0]) {
$removedIndex[] = $index;
}
}
foreach ($removedIndex as $index) {
unset($jobHandles[$index]);
}
sleep(1);
} while (true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment