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


PHP GearmanWorker::addServer方法代码示例

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


在下文中一共展示了GearmanWorker::addServer方法的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: getWorkerConnection

 /**
  * Get the GearmanWorker instance
  * 
  * @return GearmanWorker
  */
 public function getWorkerConnection()
 {
     //we have a stored connection
     if (!$this->_gmWorker) {
         //Get the config, start the client object
         $_config = $this->_getConfiguration();
         $this->_gmWorker = new GearmanWorker();
         //add the servers to the client
         foreach ($_config as $_server) {
             $this->_gmWorker->addServer($_server['host'], $_server['port']);
         }
     }
     return $this->_gmWorker;
 }
开发者ID:svenvarkel,项目名称:magento-lilmuckers_queue,代码行数:19,代码来源:Gearman.php

示例3: work

 public function work()
 {
     $config = $this->config->item('base_config');
     $host = $config['gearman']['host'];
     $port = $config['gearman']['port'];
     $worker = new GearmanWorker();
     $worker->addServer($host, $port);
     function send_request($job)
     {
         var_dump("scorpio");
         include_once APPPATH . 'third_party/snoopy.php';
         $snoopy = new Snoopy();
         $data = json_decode($job->workload());
         $method = $data->method;
         $url = $data->url;
         $params = $data->params;
         ${$method} = array();
         foreach ($params as $key => $value) {
             ${$method}[$key] = $value;
         }
         $snoopy->submit($url, ${$method});
         $result = $snoopy->results;
         return $result;
     }
     $worker->addFunction("send_request", "send_request");
     while ($worker->work()) {
     }
 }
开发者ID:sdgdsffdsfff,项目名称:hiveAdmin,代码行数:28,代码来源:gearman.php

示例4: getWorker

 /**
  * 实现单例模式
  *
  * @param   array   $config
  * @return  GearmanWorker
  */
 public static function getWorker($config)
 {
     $client = new GearmanWorker();
     foreach ($config as $serverInfo) {
         $client->addServer($serverInfo['host'], $serverInfo['port']);
     }
     return $client;
 }
开发者ID:aozhongxu,项目名称:web_hqoj,代码行数:14,代码来源:GearmanPool.class.php

示例5: indexAction

 public function indexAction()
 {
     $config = App::instance()->config;
     $worker = new GearmanWorker();
     $worker->addServer($config['gearman']['host'], $config['gearman']['port']);
     $worker->addFunction('delete_keys', array($this, 'deleteKeys'));
     $worker->addFunction('move_keys', array($this, 'moveKeys'));
     while ($worker->work()) {
     }
 }
开发者ID:xxoxx,项目名称:phpredmin,代码行数:10,代码来源:gearman.php

示例6: GearmanWorker

 function gearman_worker()
 {
     $gm = new GearmanWorker();
     $gm->addServer();
     $gm->addFunction('do_blacklist_checking', 'Monitor::do_blacklist_checking');
     $gm->addFunction('process_pending_monitor', 'Monitor::process_pending_monitor');
     while ($gm->work()) {
         echo $gm->returnCode();
     }
     exit;
 }
开发者ID:azhard4int,项目名称:AIMonitorGearman,代码行数:11,代码来源:Monitor_model.php

示例7: getWorker

 /**
  * Get GearmanWorker object.
  * @param string $queueName Queue name
  * @return \GearmanWorker
  */
 protected function getWorker($queueName)
 {
     if (!isset($this->workers[$queueName])) {
         $worker = new \GearmanWorker();
         foreach ($this->servers as $server) {
             $worker->addServer($server);
         }
         $worker->addFunction($queueName, array($this, 'work'));
         $this->workers[$queueName] = $worker;
     }
     return $this->workers[$queueName];
 }
开发者ID:rcambien,项目名称:riverline-worker-bundle,代码行数:17,代码来源:Gearman.php

示例8: executeBgTasks

 public static function executeBgTasks()
 {
     $files = scandir(self::$uploads_dir);
     unset($files[0]);
     unset($files[1]);
     $jobs = array_values($files);
     foreach ($jobs as $key => $singleJob) {
         $worker = new GearmanWorker();
         $worker->addServer();
         $worker->addFunction('q' . $key, array(new MyClass(new GearmanJob()), 'csvHandler'));
         $worker->work();
     }
 }
开发者ID:nycmic,项目名称:csv,代码行数:13,代码来源:myClass.php

示例9: actionIndex

 public function actionIndex()
 {
     $worker = new GearmanWorker();
     $worker->addServer("219.232.243.98");
     $worker->addFunction("sendMessage", function (GearmanJob $job) {
         $workload = json_decode($job->workload(), true);
         $phones = $workload['phones'];
         $content = $workload['content'];
         Yii::app()->smsClient->sendMessage($phones, $content);
         return true;
     });
     while ($worker->work()) {
     }
 }
开发者ID:qyt1988528,项目名称:union,代码行数:14,代码来源:SendMessageGearmanCommand.php

示例10: run

 public static function run()
 {
     $lockAgent = new LockAgentWorker();
     $worker = new \GearmanWorker();
     $worker->addServer();
     $worker->addFunction("findWithLock", array($lockAgent, "findWithLock"));
     $worker->addFunction("dqlWithLock", array($lockAgent, "dqlWithLock"));
     $worker->addFunction('lock', array($lockAgent, 'lock'));
     while ($worker->work()) {
         if ($worker->returnCode() != GEARMAN_SUCCESS) {
             echo "return_code: " . $worker->returnCode() . "\n";
             break;
         }
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:15,代码来源:LockAgentWorker.php

示例11: run

 public function run()
 {
     try {
         $gserver = $this->_configuration->gearman->server;
         $gport = $this->_configuration->gearman->port;
         $worker = new GearmanWorker();
         $worker->addServer($gserver, $gport);
         $jobs = $this->_configuration->job;
         $worker->addFunction($jobs->sync_search, array($this, "syncSearch"));
         while ($worker->work()) {
         }
     } catch (Exception $ex) {
         Log::dumpLog("Uncaught exception: " . $ex->getMessage(), Log::ERR);
     }
 }
开发者ID:ubriela,项目名称:solr-websearch,代码行数:15,代码来源:SyncWorker.php

示例12: worker

 /**
  * The Gearman Worker processes requests passed to it from a Gearman
  * server. This class should be invoked as a daemon using the CLI
  * interface. Multiple instances can be created to handle multiple requests
  * asynchronously.
  * 
  *      // Initialize the Gearman Worker (in bootstrap)
  *      Request_Async_Gearman::worker();
  *      exit(0);
  * 
  * To create a daemon script, run the following command from your command
  * line.
  * 
  *      php /path/to/index.php
  *
  * @return  void
  */
 public static function worker()
 {
     $worker = new GearmanWorker();
     $worker->addServer();
     $worker->addFunction('request_async', array('Request_Async_Gearman', 'execute_request'), Request_Async_Gearman::$context);
     echo Request_Async_Gearman::$context . ': Starting worker.' . "\n";
     while ($worker->work() or $worker->returnCode() == GEARMAN_IO_WAIT or $worker->returnCode() == GEARMAN_NO_JOBS) {
         if ($worker->returnCode() == GEARMAN_SUCCESS) {
             continue;
         }
         echo Request_Async_Gearman::$context . ': Waiting for next job...' . "\n";
         if (!$worker->wait()) {
             if ($worker->returnCode() == GEARMAN_NO_ACTIVE_FDS) {
                 usleep(100);
                 continue;
             }
         }
         break;
     }
     echo Request_Async_Gearman::$context . ': Stopping worker.' . "\n";
     echo Request_Async_Gearman::$context . ': Worker error' . $worker->error() . "\n";
 }
开发者ID:samsoir,项目名称:vitesse,代码行数:39,代码来源:gearman.php

示例13: actionSendPasswordEmail

    public function actionSendPasswordEmail()
    {
        $worker = new GearmanWorker();
        $worker->addServer();
        $worker->addFunction("sendPasswordEmail", function (GearmanJob $job) {
            $workload = json_decode($job->workload(), true);
            $addresses = $workload['email'];
            $id = $workload['id'];
            $token = $workload['token'];
            Yii::log(json_encode(array('token' => $token)), 'info');
            $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'union.zhantai.com';
            $link = "http://{$host}/admin/login/setPassword/id/{$id}/token/{$token}";
            $message = <<<EOT
            <p><b>亲爱的用户您好!</b></p>
            <p>这是一封铭智华通广告联盟密码设置邮件,<a target="_blank" href="{$link}">点击设置密码</a></p>
            <p>如果上述文字点击无效,请把下面网页地址复制到浏览器地址栏中打开:</p>
            <p><a target="_blank" href="{$link}">{$link}</a></p>
EOT;
            $subject = '铭智广告联盟密码设置邮件';
            return Yii::app()->mailer->send($addresses, $subject, $message);
        });
        while ($worker->work()) {
        }
    }
开发者ID:qyt1988528,项目名称:union,代码行数:24,代码来源:SendMailGearmanCommand.php

示例14: start_lib_worker

 /**
  * Starts a worker for the PECL library
  *
  * @param   array   $worker_list    List of worker functions to add
  * @return  void
  *
  */
 protected function start_lib_worker($worker_list)
 {
     $thisWorker = new GearmanWorker();
     $thisWorker->addOptions(GEARMAN_WORKER_NON_BLOCKING);
     $thisWorker->setTimeout(5000);
     foreach ($this->servers as $s) {
         $this->log("Adding server {$s}", GearmanManager::LOG_LEVEL_WORKER_INFO);
         $thisWorker->addServer($s);
     }
     foreach ($worker_list as $w) {
         $this->log("Adding job {$w}", GearmanManager::LOG_LEVEL_WORKER_INFO);
         $thisWorker->addFunction($w, array($this, "do_job"), $this);
     }
     $start = time();
     while (!$this->stop_work) {
         if (@$thisWorker->work() || $thisWorker->returnCode() == GEARMAN_IO_WAIT || $thisWorker->returnCode() == GEARMAN_NO_JOBS) {
             if ($thisWorker->returnCode() == GEARMAN_SUCCESS) {
                 continue;
             }
             if (!@$thisWorker->wait()) {
                 if ($thisWorker->returnCode() == GEARMAN_NO_ACTIVE_FDS) {
                     sleep(5);
                 }
             }
         }
         /**
          * Check the running time of the current child. If it has
          * been too long, stop working.
          */
         if ($this->max_run_time > 0 && time() - $start > $this->max_run_time) {
             $this->log("Been running too long, exiting", GearmanManager::LOG_LEVEL_WORKER_INFO);
             $this->stop_work = true;
         }
     }
     $thisWorker->unregisterAll();
 }
开发者ID:pcdinh,项目名称:GearmanManager,代码行数:43,代码来源:pecl-manager.php

示例15: action_index

	public function action_index()
	{
		// Purge and terminate ob
		while (ob_get_level()) ob_end_flush();

		# Create our worker object.
		$gearman_mworker= new GearmanWorker;

		# Add default server (localhost).
		$gearman_mworker->addServer();

		# Register function "reverse" with the server. Change the worker function to
		# "reverse_fn_fast" for a faster worker with no output.
		$gearman_mworker->addFunction("make_request", array($this, "worker"));

		while($gearman_mworker->work())
		{
			if ($gearman_mworker->returnCode() != GEARMAN_SUCCESS)
			{
				echo "return_code: " . $gearman_mworker->returnCode() . "\n";
				break;
			}
		}
	}
开发者ID:ninjapenguin,项目名称:AntFarm,代码行数:24,代码来源:worker.php


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