Created
July 6, 2011 16:55
-
-
Save YarekTyshchenko/1067754 to your computer and use it in GitHub Desktop.
Failover implementation in PEAR Net_Gearman
This file contains hidden or 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 | |
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