当前位置: 首页>>代码示例>>PHP>>正文


PHP GearmanClient::addServers方法代码示例

本文整理汇总了PHP中GearmanClient::addServers方法的典型用法代码示例。如果您正苦于以下问题:PHP GearmanClient::addServers方法的具体用法?PHP GearmanClient::addServers怎么用?PHP GearmanClient::addServers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GearmanClient的用法示例。


在下文中一共展示了GearmanClient::addServers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 public function init()
 {
     // Only use gearman implementation when WP_GEARS is defined and true
     if (!defined('WP_GEARS') || !WP_GEARS) {
         return false;
     }
     global $gearman_servers;
     if (!class_exists('GearmanClient') || !class_exists('GearmanWorker')) {
         return false;
     }
     if (defined('DOING_ASYNC') && DOING_ASYNC) {
         $this->_worker = new GearmanWorker();
         $this->_client = new GearmanClient();
         if (empty($gearman_servers)) {
             $this->_client->addServer();
             return $this->_worker->addServer();
         } else {
             $this->_client->addServers(implode(',', $gearman_servers));
             return $this->_worker->addServers(implode(',', $gearman_servers));
         }
     } else {
         $this->_client = new GearmanClient();
         if (empty($gearman_servers)) {
             $this->_client->addServer();
         } else {
             $this->_client->addServers(implode(',', $gearman_servers));
         }
         // Supressing errors, because this will return true or false, depending on if we could connect & communicate
         return @$this->_client->ping('test');
     }
 }
开发者ID:10up,项目名称:wp-gears,代码行数:31,代码来源:class-gearman-async-task.php

示例2: getClient

 /**
  * 获取gearmant客户端
  * @return \GearmanClient
  */
 private function getClient()
 {
     if ($this->client !== null) {
         return $this->client;
     }
     $client = new \GearmanClient();
     $conStrings = array();
     foreach ($this->servers as $ser) {
         if (is_string($ser)) {
             $conStrings[] = $ser;
         } else {
             $conStrings[] = $ser['host'] . (isset($ser['port']) ? ':' . $ser['port'] : '');
         }
     }
     $conString = false;
     if (count($conStrings) > 0) {
         $conString = implode(',', $conStrings);
     }
     if ($conString) {
         $result = $client->addServers($conString);
         if ($result) {
             $this->echoTraceLog('服务器添加成功! servers: ' . $conString);
         } else {
             $this->echoErrorLog('服务器添加失败! servers: ' . $conString);
             return false;
         }
     }
     $this->client = $client;
     return $this->client;
 }
开发者ID:fu-tao,项目名称:meelier_c,代码行数:34,代码来源:Client.php

示例3: init

 public function init()
 {
     $this->client = new \GearmanClient();
     $this->worker = new \GearmanWorker();
     if (empty($this->servers)) {
         $this->servers = ['127.0.0.1:4730'];
     }
     $this->client->addServers(implode(',', $this->servers));
     $this->worker->addServers(implode(',', $this->servers));
     if (!empty($this->clientOptions)) {
         $this->client->setOptions(implode(' | ', $this->clientOptions));
     }
     if (!empty($this->workerOptions)) {
         $this->worker->setOptions(implode(' | ', $this->workerOptions));
     }
 }
开发者ID:vaseninm,项目名称:yii2-gearman,代码行数:16,代码来源:GearmanComponent.php

示例4: __construct

 public function __construct(\GearmanClient $client = null)
 {
     if (is_null($client)) {
         $client = new \GearmanClient();
         $client->addServers("localhost:4730");
     }
     $this->client = $client;
 }
开发者ID:gonzalo123,项目名称:gearmanserviceprovider,代码行数:8,代码来源:GearmanServiceProvider.php

示例5: getInstance

 /**
  * This method will instantiate the object, configure it and return it
  *
  * @return Zend_Cache_Manager
  */
 public static function getInstance()
 {
     $config = App_DI_Container::get('ConfigObject');
     $gearmanClient = new GearmanClient();
     if (!empty($config->gearman->servers)) {
         $gearmanClient->addServers($config->gearman->servers->toArray());
     } else {
         $gearmanClient->addServer();
     }
     return $gearmanClient;
 }
开发者ID:omusico,项目名称:logica,代码行数:16,代码来源:GearmanClient.php

示例6: setup

 /**
  * do driver instance init
  */
 public function setup()
 {
     $settings = $this->getSettings();
     if (empty($settings)) {
         throw new BoxRouteInstanceException('init driver instance failed: empty settings');
     }
     $curInst = new \GearmanClient();
     $curInst->addServers($settings['gearmanHosts']);
     $this->instance = $curInst;
     $this->isAvailable = $this->instance ? true : false;
 }
开发者ID:nickfan,项目名称:appbox,代码行数:14,代码来源:GearmanClientBoxRouteInstanceDriver.php

示例7: run

 public function run($task)
 {
     $client = new GearmanClient();
     $client->addServers($task["server"]);
     $client->doBackground($task["cmd"], $task["ext"]);
     if (($code = $client->returnCode()) != GEARMAN_SUCCESS) {
         Main::log_write("Gearman:" . $task["cmd"] . " to " . $task["server"] . " error,code=" . $code);
         exit;
     }
     Main::log_write("Gearman:" . $task["cmd"] . " to " . $task["server"] . " success,code=" . $code);
     exit;
 }
开发者ID:royalwang,项目名称:swoole-crontab,代码行数:12,代码来源:Gearman.class.php

示例8: getClient

 /**
  * 获取客户端连接
  * @return bool|\GearmanClient
  */
 private function getClient()
 {
     if ($this->client != null) {
         return $this->client;
     }
     $client = new \GearmanClient();
     $conString = $this->conString;
     $result = $client->addServers($conString);
     if (!$result) {
         $this->logError('服务器添加失败! servers: ' . $conString);
         return false;
     }
     $this->client = $client;
     return $this->client;
 }
开发者ID:fu-tao,项目名称:meelier_c,代码行数:19,代码来源:Gearman.php

示例9: send_email

/**
 * Functions registered with the worker
 *
 * @param GearmanJob $job
 * @return boolean
 */
function send_email($job)
{
    //Get the info of the job
    $workload = unserialize($job->workload());
    //Ensure the minimum info
    if (!array_key_exists('text', $workload) && !array_key_exists('html', $workload)) {
        echo sprintf("%s: To send an email we need at least the text or html\n", date('r'));
        $job->sendFail();
        return FALSE;
    }
    if (!array_key_exists('to', $workload) || array_key_exists('to', $workload) && empty($workload['to'])) {
        echo sprintf("%s: To send an email we need the recipient address\n", date('r'));
        $job->sendFail();
        return FALSE;
    }
    if (!array_key_exists('subject', $workload)) {
        echo sprintf("%s: To send an email we need the subject of the email\n", date('r'));
        $job->sendFail();
        return FALSE;
    }
    echo sprintf("%s: Received a task to send email to %s\n", date('r'), implode(', ', is_array($workload['to']) ? $workload['to'] : array($workload['to'])));
    $config = getConfig();
    $mail = new Zend_Mail('utf-8');
    if ($config->system->email_system->send_by_amazon_ses) {
        $transport = new App_Mail_Transport_AmazonSES(array('accessKey' => $config->amazon->aws_access_key, 'privateKey' => $config->amazon->aws_private_key));
    }
    if (array_key_exists('text', $workload)) {
        $mail->setBodyText($workload['text']);
    }
    if (array_key_exists('html', $workload)) {
        $mail->setBodyHtml($workload['html']);
    }
    if (array_key_exists('reply', $workload) && !empty($workload['reply'])) {
        $mail->setReplyTo($workload['reply']);
    }
    $mail->setFrom($config->amazon->ses->from_address, $config->amazon->ses->from_name);
    $mail->addTo($workload['to']);
    $mail->setSubject($workload['subject']);
    //Prepare gearman client
    $config = getConfig();
    $gearmanClient = new GearmanClient();
    if (!empty($config->gearman->servers)) {
        $gearmanClient->addServers($config->gearman->servers->toArray());
    } else {
        $gearmanClient->addServer();
    }
    //Add the callbacks
    $gearmanClient->setCompleteCallback('taskCompleted');
    $gearmanClient->setFailCallback('taskFailed');
    try {
        if (isset($transport) && $transport instanceof App_Mail_Transport_AmazonSES) {
            $mail->send($transport);
        } else {
            $mail->send();
        }
        //Some status info
        echo sprintf("%s: Email (%s) sent to %s\n", date('r'), $workload['subject'], implode(', ', is_array($workload['to']) ? $workload['to'] : array($workload['to'])));
        echo sprintf("%s: Task finished successfully\n\n", date('r'));
        $job->sendComplete(TRUE);
        return TRUE;
    } catch (Exception $e) {
        logError(sprintf("Error while sending an email to %s.\n\nError: %s\n", $workload['to'], $e->getMessage()));
        $job->sendFail();
        return FALSE;
    }
}
开发者ID:omusico,项目名称:logica,代码行数:72,代码来源:SendEmailWorker.php

示例10: work


//.........这里部分代码省略.........
                     $rname = trim($m['rname']);
                     $files[] = "{$fname}#('bidinfo','{$fname}','{$rname}')";
                 }
             }
             $data['attchd_lnk'] = implode('|', $files);
             $html = strip_tags($html, '<th><tr><td>');
             //공고종류
             $p = '#공고종류</th> <td>(?<bidproc>[^<]*)</td>#i';
             $data['bidproc'] = self::match($p, $html, 'bidproc');
             //공고명
             $p = '#입찰공고건명</th> <td>(?<constnm>.+)본 공고는 지문인식#i';
             $data['constnm'] = self::match($p, $html, 'constnm');
             //공고부서
             $p = '#공고부서</th> <td>(?<org>[^<]*)</td>#i';
             $data['org'] = self::match($p, $html, 'org');
             //추정가격
             $p = '#추정가격</th> <td>(?<presum>\\d+(,\\d{1,3})*)원#i';
             $data['presum'] = self::match($p, $html, 'presum');
             //기초금액
             $p = '#기초금액</th> <td>(?<basic>\\d+(,\\d{1,3})*)원#i';
             $data['basic'] = self::match($p, $html, 'basic');
             //계약방법
             $p = '#계약방법</th> <td>(?<contract>[^<]*)</td>#i';
             $data['contract'] = self::match($p, $html, 'contract');
             //입찰방식
             $p = '#입찰방식</th> <td>(?<bidcls>[^<]*)</td>#i';
             $data['bidcls'] = self::match($p, $html, 'bidcls');
             //낙찰자선정방법
             $p = '#낙찰자선정방법</th> <td>(?<succls>[^<]*)</td>#i';
             $data['succls'] = self::match($p, $html, 'succls');
             //공동수급협정서접수마감일시
             $p = '#공동수급협정서접수마감일시</th> <td>(?<hyupenddt>[^<]*)</td>#i';
             $data['hyupenddt'] = self::match($p, $html, 'hyupenddt');
             //입찰서접수개시일시
             $p = '#입찰서접수개시일시</th> <td>(?<opendt>[^<]*)</td>#i';
             $data['opendt'] = self::match($p, $html, 'opendt');
             //입찰서접수마감일시
             $p = '#입찰서접수마감일시</th> <td>(?<closedt>[^<]*)</td>#i';
             $data['closedt'] = self::match($p, $html, 'closedt');
             //입찰참가신청서접수마감일시
             $p = '#입찰참가신청서접수마감일시</th> <td>(?<registdt>[^<]*)</td>#i';
             $data['registdt'] = self::match($p, $html, 'registdt');
             //개찰일시
             $p = '#개찰일시</th> <td>(?<constdt>[^<]*)</td>#i';
             $data['constdt'] = self::match($p, $html, 'constdt');
             //현장설명일시
             $p = '#현장설명일시</th> <td>(?<explaindt>[^<]*)</td>#i';
             $data['explaindt'] = self::match($p, $html, 'explaindt');
             //공고변경사유
             $p = '#공고변경사유</th> <td>(?<bidcomment_mod>[^<]*)</td>#i';
             $data['bidcomment_bid'] = self::match($p, $html, 'bidcomment_mod');
             //투찰제한
             $p = '#투찰제한정보 <tr>' . ' <th>참가지역1</th> <td>(?<local1>[^<]*)</td>' . ' <th>참가지역2</th> <td>(?<local2>[^<]*)</td>' . ' <th>참가지역3</th> <td>(?<local3>[^<]*)</td>' . ' <th>참가지역4</th> <td>(?<local4>[^<]*)</td>' . ' </tr>#i';
             $p = str_replace(' ', '\\s*', $p);
             if (preg_match($p, $html, $m)) {
                 $data['local1'] = trim($m['local1']);
                 $data['local2'] = trim($m['local2']);
                 $data['local3'] = trim($m['local3']);
                 $data['local4'] = trim($m['local4']);
             }
             //지역의무공동업체제한
             $p = '#지역의무공동업체제한 <tr>' . ' <th>참가지역1</th> <td>(?<local1>[^<]*)</td>' . ' <th>참가지역2</th> <td>(?<local2>[^<]*)</td>' . ' <th>참가지역3</th> <td>(?<local3>[^<]*)</td>' . ' <th>참가지역4</th> <td>(?<local4>[^<]*)</td>' . ' </tr>#i';
             $p = str_replace(' ', '\\s*', $p);
             if (preg_match($p, $html, $m)) {
                 $data['contloc1'] = trim($m['local1']);
                 $data['contloc2'] = trim($m['local2']);
                 $data['contloc3'] = trim($m['local3']);
                 $data['contloc4'] = trim($m['local4']);
             }
             print_r($data);
             if (strpos($data['bidproc'], '취소공고') !== false) {
                 $bidproc = 'C';
             } else {
                 $bidproc = 'B';
             }
             $bidkey = BidKey::findOne(['whereis' => '05', 'notinum' => $workload['notinum'] . '-' . $workload['subno'], 'bidproc' => $bidproc]);
             if ($bidkey === null) {
                 if (strpos($data['bidproc'], '취소공고') !== false) {
                     $bidproc = 'C';
                 }
             }
             $pub->publish($channel . '-client', ['url' => 'close', 'post' => '']);
             $redis->close();
             return;
         });
     } catch (PassException $e) {
     } catch (\RedisException $e) {
         $sub->close();
         echo Console::renderColoredString('%r' . $e->getMessage() . '%n'), PHP_EOL;
         $gman_client = new \GearmanClient();
         $gman_client->addServers($module->gman_server);
         $gman_client->doBackground('ebidlh_bid_work', $job->workload());
     } catch (\Exception $e) {
         $sub->close();
         echo Console::renderColoredString("%r{$e}%n"), PHP_EOL;
         \Yii::error($job->workload() . "\n" . $e, 'ebidlh');
     }
     $module->db->close();
     echo Console::renderColoredString("%c" . sprintf("[%s] Peak memory usage: %sMb", date('Y-m-d H:i:s'), memory_get_peak_usage(true) / 1024 / 1024) . "%n"), PHP_EOL;
 }
开发者ID:didwjdgks,项目名称:yii2-ebid-lh,代码行数:101,代码来源:BidWorker.php

示例11: init

 public function init()
 {
     parent::init();
     $gman_client = new \GearmanClient();
     $gman_client->addServers('115.168.48.242');
 }
开发者ID:didwjdgks,项目名称:yii2-kwater,代码行数:6,代码来源:WorkController.php

示例12: __property_client

 protected function __property_client()
 {
     $return = new \GearmanClient();
     $return->addServers($this->server);
     return $return;
 }
开发者ID:noframework,项目名称:noframework,代码行数:6,代码来源:Wrapper.php

示例13: client

 /**
  * 
  * @return \GearmanClient
  */
 public function client()
 {
     $gmClient = new \GearmanClient();
     $gmClient->addServers(GEARMAN_SERVERS);
     return $gmClient;
 }
开发者ID:im286er,项目名称:ent,代码行数:10,代码来源:Gearman.php

示例14: client

 /**
  * @return \GearmanClient
  * @throws MQException
  */
 protected function client()
 {
     $client = new \GearmanClient();
     $client->addServers($this->dns);
     if (($haveGoodServer = $client->ping($this->id)) === false) {
         throw new MQException("Server does not access: {$this->dns}");
     }
     return $client;
 }
开发者ID:romeoz,项目名称:rock-mq,代码行数:13,代码来源:GearmanQueue.php

示例15: sendMessage

 public function sendMessage($msg)
 {
     $gman = new \GearmanClient();
     $gman->addServers('115.68.48.242');
     $gman->doBackground('send_chat_message_from_admin', Json::encode(['recv_id' => 149, 'message' => $msg]));
 }
开发者ID:didwjdgks,项目名称:yii2-ebid-ex,代码行数:6,代码来源:BidController.php


注:本文中的GearmanClient::addServers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。