Created
August 24, 2011 21:49
-
-
Save hjr3/1169348 to your computer and use it in GitHub Desktop.
Complete Gearman example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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