protected function start_lib_worker($worker_list, $timeouts = array()) {

        /**
         * Require PEAR Net_Gearman libs
         */
        define('NET_GEARMAN_JOB_PATH', $this->worker_dir);

        if (!class_exists("Net_Gearman_Job_Common")) {
            require "Net/Gearman/Job/Common.php";
        }

        if (!class_exists("Net_Gearman_Job")) {
            require "Net/Gearman/Job.php";
        }

        if (!class_exists("Net_Gearman_Worker")) {
            require "Net/Gearman/Worker.php";
        }

        try {

            $this->worker = new \Net_Gearman_Worker($this->servers);

        } catch (Net_Gearman_Exception $e) {

            $this->log($e->getMessage(), GearmanManager::LOG_LEVEL_WORKER_INFO);
            return;

        }

        $server_status = $this->worker->connection_status();

        if ($server_status["connected"] == 0) {
            $this->log("Failed to connect to any servers", GearmanManager::LOG_LEVEL_WORKER_INFO);
        } elseif ($server_status["disconnected"] > 0) {
            $message = "Failed to connect to the following servers: ";
            foreach ($server_status["servers"] as $server => $status) {
                if (!$status) {
                    $message.= "$server,";
                }
            }
            $message = substr($message, 0, -1);
            $this->log($message, GearmanManager::LOG_LEVEL_WORKER_INFO);
        }

        foreach ($worker_list as $w) {
            $timeout = (isset($timeouts[$w]) ? $timeouts[$w] : null);
            $message = "Adding job $w";
            if ($timeout) {
                $message.= "; timeout: $timeout";
            }
            $this->log($message, GearmanManager::LOG_LEVEL_WORKER_INFO);
            $this->worker->addAbility($w, $timeout, $this->functions[$w]);
        }

        $this->worker->attachCallback(array($this, 'job_start'), \Net_Gearman_Worker::JOB_START);
        $this->worker->attachCallback(array($this, 'job_complete'), \Net_Gearman_Worker::JOB_COMPLETE);
        $this->worker->attachCallback(array($this, 'job_fail'), \Net_Gearman_Worker::JOB_FAIL);

        $this->start_time = time();

        $this->worker->beginWork(array($this, "monitor"));

    }
protected function start_lib_worker($worker_list, $timeouts = array()) {

        /**
         * Require PEAR Net_Gearman libs
         */
        define('NET_GEARMAN_JOB_PATH', $this->worker_dir);

        if (!class_exists("Net_Gearman_Job_Common")) {
            require "Net/Gearman/Job/Common.php";
        }

        if (!class_exists("Net_Gearman_Job")) {
            require "Net/Gearman/Job.php";
        }

        if (!class_exists("Net_Gearman_Worker")) {
            require "Net/Gearman/Worker.php";
        }

        try {

            $this->worker = new \Net_Gearman_Worker($this->servers);

        } catch (Net_Gearman_Exception $e) {

            $this->log($e->getMessage(), GearmanManager::LOG_LEVEL_WORKER_INFO);
            return;

        }

        $server_status = $this->worker->connection_status();

        if ($server_status["connected"] == 0) {
            $this->log("Failed to connect to any servers", GearmanManager::LOG_LEVEL_WORKER_INFO);
        } elseif ($server_status["disconnected"] > 0) {
            $message = "Failed to connect to the following servers: ";
            foreach ($server_status["servers"] as $server => $status) {
                if (!$status) {
                    $message.= "$server,";
                }
            }
            $message = substr($message, 0, -1);
            $this->log($message, GearmanManager::LOG_LEVEL_WORKER_INFO);
        }

        foreach ($worker_list as $w) {
            $timeout = (isset($timeouts[$w]) ? $timeouts[$w] : null);
            $message = "Adding job $w";
            if ($timeout) {
                $message.= "; timeout: $timeout";
            }
            $this->log($message, GearmanManager::LOG_LEVEL_WORKER_INFO);
            $this->worker->addAbility($w, $timeout, $this->functions[$w]);
        }

        $this->worker->attachCallback(array($this, 'job_start'), \Net_Gearman_Worker::JOB_START);
        $this->worker->attachCallback(array($this, 'job_complete'), \Net_Gearman_Worker::JOB_COMPLETE);
        $this->worker->attachCallback(array($this, 'job_fail'), \Net_Gearman_Worker::JOB_FAIL);

        $this->start_time = time();

        $this->worker->beginWork(array($this, "monitor"));

    }
protected function start_lib_worker ( $ worker_list , $ timeouts = array ( ) ) { /**
         * Require PEAR Net_Gearman libs
         */ define ( 'NET_GEARMAN_JOB_PATH' , $ this -> worker_dir ) ; if ( ! class_exists ( "Net_Gearman_Job_Common" ) ) { require "Net/Gearman/Job/Common.php" ; } if ( ! class_exists ( "Net_Gearman_Job" ) ) { require "Net/Gearman/Job.php" ; } if ( ! class_exists ( "Net_Gearman_Worker" ) ) { require "Net/Gearman/Worker.php" ; } try { $ this -> worker = new \ Net_Gearman_Worker ( $ this -> servers ) ; } catch ( Net_Gearman_Exception $ e ) { $ this -> log ( $ e -> getMessage ( ) , GearmanManager :: LOG_LEVEL_WORKER_INFO ) ; return ; } $ server_status = $ this -> worker -> connection_status ( ) ; if ( $ server_status [ "connected" ] == 0 ) { $ this -> log ( "Failed to connect to any servers" , GearmanManager :: LOG_LEVEL_WORKER_INFO ) ; } elseif ( $ server_status [ "disconnected" ] > 0 ) { $ message = "Failed to connect to the following servers: " ; foreach ( $ server_status [ "servers" ] as $ server => $ status ) { if ( ! $ status ) { $ message .= "$server," ; } } $ message = substr ( $ message , 0 , - 1 ) ; $ this -> log ( $ message , GearmanManager :: LOG_LEVEL_WORKER_INFO ) ; } foreach ( $ worker_list as $ w ) { $ timeout = ( isset ( $ timeouts [ $ w ] ) ? $ timeouts [ $ w ] : null ) ; $ message = "Adding job $w" ; if ( $ timeout ) { $ message .= "; timeout: $timeout" ; } $ this -> log ( $ message , GearmanManager :: LOG_LEVEL_WORKER_INFO ) ; $ this -> worker -> addAbility ( $ w , $ timeout , $ this -> functions [ $ w ] ) ; } $ this -> worker -> attachCallback ( array ( $ this , 'job_start' ) , \ Net_Gearman_Worker :: JOB_START ) ; $ this -> worker -> attachCallback ( array ( $ this , 'job_complete' ) , \ Net_Gearman_Worker :: JOB_COMPLETE ) ; $ this -> worker -> attachCallback ( array ( $ this , 'job_fail' ) , \ Net_Gearman_Worker :: JOB_FAIL ) ; $ this -> start_time = time ( ) ; $ this -> worker -> beginWork ( array ( $ this , "monitor" ) ) ; }
Starts a worker for the PEAR library

@param   array   $worker_list    List of worker functions to add
@param   array   $timeouts       list of worker timeouts to pass to server
@return  void
Starts a worker for the PEAR library