Skip to content

Instantly share code, notes, and snippets.

@hjr3
Created August 24, 2011 21:49
Show Gist options
  • Save hjr3/1169348 to your computer and use it in GitHub Desktop.
Save hjr3/1169348 to your computer and use it in GitHub Desktop.
Complete Gearman example
<?php
// client
$gmc= new GearmanClient();
$gmc->addServer();
$gmc->setExceptionCallback(function(GearmanTask $task) {
$m = $task->data();
echo "Exception: {$m}\n";
return GEARMAN_WORK_EXCEPTION;
});
$workload = array(
'member_id' => 12345,
'device_token' => 'abcdefg',
'message' => 'test message',
'scheduled_time' => date('c')
);
$gmc->do('push_notification', json_encode($workload));
?>
<?php
// worker
$gmw = new GearmanWorker();
$gmw->addServer();
$gmw->addFunction('push_notification', function(GearmanJob $job) {
$workload = json_decode($job->workload());
var_dump($workload);
});
while(1) $gmw->work();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment