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


PHP GearmanWorker::addOptions方法代码示例

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


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

示例1: worker

 /**
  * @return GearmanWorker
  */
 public function worker()
 {
     if (!$this->worker) {
         $this->worker = $this->setServers(new \GearmanWorker());
     }
     $this->worker->addOptions(GEARMAN_WORKER_GRAB_UNIQ);
     return $this->worker;
 }
开发者ID:perspectivain,项目名称:yii2-gearman,代码行数:11,代码来源:Gearman.php

示例2: _work

 /**
  * Set up the GearmanWorker to run in non-blocking mode
  *
  * This allows you to do work "in between" jobs when its idle
  *
  * Events emitted:
  *  - Gearman.beforeWork: Called before GearmanWorker::work()
  *  - Gearman.afterWork: Called after GearmanWorker::work() actually processed a job
  *  - Gearman.beforeWait: Called before Gearman::wait() is called
  *  - Gearman.afterWait: Called after Gearman::wait() is called
  *
  * N.B: Gearman.beforeWork will be called even if there is no jobs to be processed,
  * it's meant as a simple wrapper around GearmanWorker::work() and GearmanWorker::wait()
  *
  * All events can abort the infinite loop by calling $event->stopPropagation();
  *
  * @return void
  */
 protected function _work()
 {
     $this->_worker->addOptions(GEARMAN_WORKER_NON_BLOCKING);
     // Infinite loop of doom until we die!
     while (true) {
         if (!$this->_triggerEvent('Gearman.beforeWork')) {
             break;
         }
         $this->_worker->work();
         if (!$this->_triggerEvent('Gearman.afterWork')) {
             break;
         }
         // If we processed a job, don't bother to wait
         if ($this->_worker->returnCode() == GEARMAN_SUCCESS) {
             continue;
         }
         if (!$this->_triggerEvent('Gearman.beforeWait')) {
             break;
         }
         $this->_worker->wait();
         if (!$this->_triggerEvent('Gearman.afterWait')) {
             break;
         }
     }
 }
开发者ID:nodesagency,项目名称:Platform-Common-Plugin,代码行数:43,代码来源:GearmanWorkerTask.php

示例3: start_lib_worker

 /**
  * Starts a worker for the PECL library
  *
  * @param   array   $worker_list    List of worker functions to add
  * @param   array   $timeouts       list of worker timeouts to pass to server
  * @return  void
  *
  */
 protected function start_lib_worker($worker_list, $timeouts = array())
 {
     $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);
         // see: https://bugs.php.net/bug.php?id=63041
         try {
             $thisWorker->addServers($s);
         } catch (\GearmanException $e) {
             if ($e->getMessage() !== 'Failed to set exception option') {
                 throw $e;
             }
         }
     }
     foreach ($worker_list as $w) {
         $timeout = isset($timeouts[$w]) ? $timeouts[$w] : null;
         $this->log("Adding job {$w} ; timeout: " . $timeout, GearmanManager::LOG_LEVEL_WORKER_INFO);
         $thisWorker->addFunction($w, array($this, "do_job"), $this, $timeout);
     }
     $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;
         }
         if (!empty($this->config["max_runs_per_worker"]) && $this->job_execution_count >= $this->config["max_runs_per_worker"]) {
             $this->log("Ran {$this->job_execution_count} jobs which is over the maximum({$this->config['max_runs_per_worker']}), exiting", GearmanManager::LOG_LEVEL_WORKER_INFO);
             $this->stop_work = true;
         }
     }
     $thisWorker->unregisterAll();
 }
开发者ID:productsupcom,项目名称:gearmanmanager,代码行数:56,代码来源:GearmanPeclManager.php

示例4: work

 public function work(\GearmanWorker $worker)
 {
     $worker->addOptions(GEARMAN_WORKER_NON_BLOCKING);
     $getWorkAttempts = 0;
     do {
         $workRes = $worker->work();
         $getWorkAttempts++;
         $this->logger->debug("Get work attempt res: " . serialize($workRes));
         $this->logger->debug("Attempts number: " . serialize($getWorkAttempts));
         sleep(1);
         if ($workRes) {
             $this->taskWasGot = true;
         }
     } while ($workRes === false && $getWorkAttempts < WorkersConstants::MAX_GET_TASK_ATTEMPTS);
     if ($worker->returnCode() != GEARMAN_SUCCESS) {
         $this->logger->error("Not correct Gearman worker execution:" . $worker->returnCode());
     }
     return null;
 }
开发者ID:jamset,项目名称:gearman-conveyor,代码行数:19,代码来源:BaseCommonWorker.php

示例5: 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->addServers($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;
         }
         if (!empty($this->config["max_runs_per_worker"]) && $this->job_execution_count >= $this->config["max_runs_per_worker"]) {
             $this->log("Ran {$this->job_execution_count} jobs which is over the maximum({$this->config['max_runs_per_worker']}), exiting", GearmanManager::LOG_LEVEL_WORKER_INFO);
             $this->stop_work = true;
         }
     }
     $thisWorker->unregisterAll();
 }
开发者ID:roadrunner,项目名称:GearmanManager,代码行数:47,代码来源:pecl-manager.php

示例6: GearmanWorker

<?php 

// Instantiate a new Gearman Worker
$worker= new GearmanWorker();

// Non-blocking
$worker->addOptions(GEARMAN_WORKER_NON_BLOCKING); 

// Add the localhost:4730 as server (default)
$worker->addServer(); 

// Add the functions to the worker
// Fetch all photo Ids of this twitpic user
$worker->addFunction("fetchPhotoIds", "fetchPhotoIds");

// Fetch a photo from twitpic
$worker->addFunction("fetchPhoto", "fetchPhoto");

// This worker will destroy itself in 5 seconds.
$worker->setTimeout(5000);

// Keep worker alive as long as there are jobs
while (@$worker->work() || $worker->returnCode() == GEARMAN_IO_WAIT || 
		$worker->returnCode() == GEARMAN_NO_JOBS){
			
	if ($worker->returnCode() == GEARMAN_SUCCESS){
		echo date('d-m-Y H:i:s') . "| Job Successful \n";
		continue;
	}
	
	if (!@$worker->wait()) { 
开发者ID:ntulip,项目名称:Twitpic-Fetcher,代码行数:31,代码来源:twitpic_worker.php


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