Skip to content

Instantly share code, notes, and snippets.

@YarekTyshchenko
Created July 6, 2011 16:55
Show Gist options
  • Save YarekTyshchenko/1067754 to your computer and use it in GitHub Desktop.
Save YarekTyshchenko/1067754 to your computer and use it in GitHub Desktop.
Failover implementation in PEAR Net_Gearman
<?php
require_once 'Net/Gearman/Client.php';
while (true) {
while (!process('reverse', 'hellp'));
echo '.';
}
$gc = null;
function process($function, $data) {
global $gc;
try {
if(!$gc) {
$gc = new Net_Gearman_Client(array(
'10.0.30.182:4730',
'10.0.30.181:4730',
));
}
$set = new Net_Gearman_Set();
$task = new Net_Gearman_Task($function, $data);
$set->addTask($task);
$gc->runSet($set);
return true;
} catch (Net_Gearman_Exception $e) {
$gc = false;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment