I\'m having a problem with gearman workers running on multiple servers which i can\'t seem to solve.
The problem occurs when a worker server is taken offline, rather tha
since 'addServer' from gearman client is not working properly this code can choose a jobserver randomly and if fails try the next one, this way you can balance the load.
// job servers
$jobservers = array('192.168.1.1','192.168.1.2');
// prepare gearman client
$gmclient = new GearmanClient();
// shuffle job servers (deliver jobs equally by server)
shuffle($jobservers);
// add job servers
foreach($jobservers as $jobserver) {
// add random jobserver
$gmclient->addServer($jobserver);
// check server state if ok end foreach
if (@$gmclient->ping('ping')) break;
// if connections fails reset client
$gmclient = new GearmanClient();
}