Gearman with multiple servers and php workers

后端 未结 5 1911
误落风尘
误落风尘 2021-02-02 01:57

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

5条回答
  •  孤独总比滥情好
    2021-02-02 02:29

    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();
            }
    

提交回复
热议问题