本文整理汇总了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');
}
}
示例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;
}
示例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));
}
}
示例4: __construct
public function __construct(\GearmanClient $client = null)
{
if (is_null($client)) {
$client = new \GearmanClient();
$client->addServers("localhost:4730");
}
$this->client = $client;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例11: init
public function init()
{
parent::init();
$gman_client = new \GearmanClient();
$gman_client->addServers('115.168.48.242');
}
示例12: __property_client
protected function __property_client()
{
$return = new \GearmanClient();
$return->addServers($this->server);
return $return;
}
示例13: client
/**
*
* @return \GearmanClient
*/
public function client()
{
$gmClient = new \GearmanClient();
$gmClient->addServers(GEARMAN_SERVERS);
return $gmClient;
}
示例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;
}
示例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]));
}