Skip to content

Instantly share code, notes, and snippets.

@daum
Created February 27, 2014 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daum/9260047 to your computer and use it in GitHub Desktop.
Save daum/9260047 to your computer and use it in GitHub Desktop.
<?php
// In controller...
public function getReportAcrossDatabasesAction(Request $request)
{
// Listen for Gearman to notify that it has data from a completed job.
$this->get('event_dispatcher')
->addListener('gearman.client.callback.complete',array($this,'gearmanCallback'));
$gearman = $this->get('gearman');
//Assume $request->request->get('connectionIds') is list of connections.
foreach($request->request->get('connectionIds') as $connID)
{
$gearman->addTask('MyDemoBundleWorker~gatherVastAmountsOfData',array(json_encode('connection_id'=>$connId)));
}
$gearman->runTasks();
$totalRowCount = 0;
foreach($this->callbackData as $data)
{
$totalRowCount+= $data['total'];
}
return array('totalRowCount'=>$totalRowCount);
}
public function gearmanCallback(GearmanClientCallbackCompleteEvent $e)
{
$this->callbackData[] = json_decode($e->getGearmanTask()->data(),true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment