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


PHP GearmanWorker::returnCode方法代码示例

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


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

示例1: __construct

 /**
  * Constructor
  * Checks for the required gearman extension,
  * fetches the bootstrap and loads in the gearman worker
  *
  * @return Gearman_Worker
  */
 public function __construct($bootstrap)
 {
     if (!extension_loaded('gearman')) {
         throw new RuntimeException('The PECL::gearman extension is required.');
     }
     $this->_worker = $bootstrap->getWorker();
     if (empty($this->_registerFunction)) {
         throw new InvalidArgumentException(get_class($this) . ' must implement a registerFunction');
     }
     // allow for a small memory gap:
     $memoryLimit = ($this->_memory + 128) * 1024 * 1024;
     ini_set('memory_limit', $memoryLimit);
     $this->_worker->addFunction($this->_registerFunction, array(&$this, 'work'));
     $this->_worker->setTimeout($this->_timeout);
     $this->init();
     while ($this->_worker->work() || $this->_worker->returnCode() == GEARMAN_TIMEOUT) {
         if ($this->_worker->returnCode() == GEARMAN_TIMEOUT) {
             $this->timeout();
             continue;
         }
         if ($this->_worker->returnCode() != GEARMAN_SUCCESS) {
             $this->setError($this->_worker->returnCode() . ': ' . $this->_worker->getErrno() . ': ' . $this->_worker->error());
             break;
         }
     }
     $this->shutdown();
 }
开发者ID:omusico,项目名称:logica,代码行数:34,代码来源:Worker.php

示例2: 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

示例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: __construct

 /**
  * Constructor
  * Checks for the required gearman extension,
  * fetches the bootstrap and loads in the gearman worker
  *
  * @param Zend_Application_Bootstrap_BootstrapAbstract $bootstrap
  * @return Zend_Gearman_Worker
  */
 public function __construct(Zend_Application_Bootstrap_BootstrapAbstract $bootstrap)
 {
     if (!extension_loaded('gearman')) {
         throw new RuntimeException('The PECL::gearman extension is required.');
     }
     $this->_bootstrap = $bootstrap;
     $this->_worker = $this->_bootstrap->bootstrap('gearmanworker')->getResource('gearmanworker');
     if (empty($this->_registerFunction)) {
         throw new InvalidArgumentException(get_class($this) . ' must implement a registerFunction');
     }
     // allow for a small memory gap:
     $memoryLimit = ($this->_memory + 128) * 1024 * 1024;
     ini_set('memory_limit', $memoryLimit);
     $this->_worker->addFunction($this->_registerFunction, array(&$this, 'work'));
     $this->_worker->setTimeout($this->_timeout);
     $this->init();
     $check = 10;
     $c = 0;
     while (@$this->_worker->work() || $this->_worker->returnCode() == GEARMAN_TIMEOUT) {
         $c++;
         if ($this->_worker->returnCode() == GEARMAN_TIMEOUT) {
             $this->timeout();
             continue;
         }
         if ($this->_worker->returnCode() != GEARMAN_SUCCESS) {
             $this->setError($this->_worker->returnCode() . ': ' . $this->_worker->getErrno() . ': ' . $this->_worker->error());
             break;
         }
         if ($c % $check === 0 && $this->isMemoryOverflow()) {
             break;
             // we've consumed our memory and the worker needs to be restarted
         }
     }
     $this->shutdown();
 }
开发者ID:nguyenduong127,项目名称:Project-dll.vn-,代码行数:43,代码来源:Worker.php

示例5: _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

示例6: listen

 function listen()
 {
     foreach ($this->getConfiguration()->getFunctions() as $functionName => $callable) {
         $this->worker->addFunction($functionName, $this->wrap($callable, $functionName));
     }
     $this->suppressListen();
     $started = time();
     while ($this->worker->work()) {
         if ($this->worker->returnCode() != GEARMAN_SUCCESS) {
             $this->getLogger()->error('Gearman success fail with code:' . $this->worker->returnCode());
             $this->terminate(SIGTERM);
         }
         $this->suppressListen();
         $this->checkMatchedConditions();
         if (time() - $started < 1) {
             sleep(1);
         }
     }
 }
开发者ID:ephrin,项目名称:samples,代码行数:19,代码来源:WorkerDaemon.php

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: work

 protected function work(\GearmanWorker $worker)
 {
     // @!?
     if (@$worker->work()) {
         return true;
     }
     switch ($worker->returnCode()) {
         case GEARMAN_SUCCESS:
         case GEARMAN_TIMEOUT:
             return true;
         case GEARMAN_IO_WAIT:
         case GEARMAN_NO_JOBS:
             return $this->wait($worker);
         default:
             break;
     }
     return false;
 }
开发者ID:JaredWilliams,项目名称:PHPGearmanToolkit,代码行数:18,代码来源:ProcessControl.php

示例13: runJob

 /**
  * Given a GearmanWorker and an instance of Job, run it
  *
  * @param \GearmanWorker $gearmanWorker Gearman Worker
  * @param Object         $objInstance   Job instance
  * @param array          $jobs          Array of jobs to subscribe
  * @param integer        $iterations    Number of iterations
  * @param integer        $timeout       Timeout
  *
  * @return GearmanExecute self Object
  */
 private function runJob(\GearmanWorker $gearmanWorker, $objInstance, array $jobs, $iterations, $timeout = null)
 {
     /**
      * Set the output of this instance, this should allow workers to use the console output.
      */
     if ($objInstance instanceof GearmanOutputAwareInterface) {
         $objInstance->setOutput($this->output ?: new NullOutput());
     }
     /**
      * Every job defined in worker is added into GearmanWorker
      */
     foreach ($jobs as $job) {
         /**
          * worker needs to have it's context into separated memory space;
          * if it's passed as a value, then garbage collector remove the target
          * what causes a segfault
          */
         $this->workersBucket[$job['realCallableName']] = array('job_object_instance' => $objInstance, 'job_method' => $job['methodName'], 'jobs' => $jobs);
         $gearmanWorker->addFunction($job['realCallableName'], array($this, 'handleJob'));
     }
     /**
      * If iterations value is 0, is like worker will never die
      */
     $alive = 0 === $iterations;
     if ($timeout > 0) {
         $gearmanWorker->setTimeout($timeout * 1000);
     }
     /**
      * Executes GearmanWorker with all jobs defined
      */
     while (false === $this->stopWorkSignalReceived && $gearmanWorker->work()) {
         $iterations--;
         $event = new GearmanWorkExecutedEvent($jobs, $iterations, $gearmanWorker->returnCode());
         $this->eventDispatcher->dispatch(GearmanEvents::GEARMAN_WORK_EXECUTED, $event);
         if ($gearmanWorker->returnCode() != GEARMAN_SUCCESS) {
             break;
         }
         /**
          * Only finishes its execution if alive is false and iterations
          * arrives to 0
          */
         if (!$alive && $iterations <= 0) {
             break;
         }
     }
 }
开发者ID:WayOfBrave,项目名称:GearmanBundle,代码行数:57,代码来源:GearmanExecute.php

示例14: function

#!/usr/bin/env php
<?php 
namespace phinde;

chdir(dirname($argv[0]));
require_once __DIR__ . '/../src/init.php';
$gmworker = new \GearmanWorker();
$gmworker->addServer('127.0.0.1');
$gmworker->addFunction($GLOBALS['phinde']['queuePrefix'] . 'phinde_process', function (\GearmanJob $job) {
    $data = unserialize($job->workload());
    Log::info("-- Processing " . $data['url'] . ' (' . implode(',', $data['actions']) . ')');
    passthru('./process.php ' . escapeshellarg($data['url']) . ' ' . implode(' ', $data['actions']));
});
$gmworker->addFunction($GLOBALS['phinde']['queuePrefix'] . 'phinde_quit', function (\GearmanJob $job) {
    Log::info('Got exit job');
    $job->sendComplete('');
    exit(0);
});
while ($gmworker->work()) {
    if ($gmworker->returnCode() != GEARMAN_SUCCESS) {
        Log::error('Error running job: ' . $gmworker->returnCode());
        break;
    }
}
开发者ID:cweiske,项目名称:phinde,代码行数:24,代码来源:phinde-worker.php

示例15: runJob

 /**
  * Given a GearmanWorker and an instance of Job, run it
  *
  * @param \GearmanWorker $gearmanWorker Gearman Worker
  * @param Object         $objInstance   Job instance
  * @param array          $jobs          Array of jobs to subscribe
  * @param integer        $iterations    Number of iterations
  *
  * @return GearmanExecute self Object
  */
 private function runJob(\GearmanWorker $gearmanWorker, $objInstance, array $jobs, $iterations)
 {
     /**
      * Set the output of this instance, this should allow workers to use the console output.
      */
     if ($objInstance instanceof GearmanOutputAwareInterface) {
         $objInstance->setOutput($this->output ?: new NullOutput());
     }
     /**
      * Every job defined in worker is added into GearmanWorker
      */
     foreach ($jobs as $job) {
         $gearmanWorker->addFunction($job['realCallableName'], array($objInstance, $job['methodName']));
     }
     /**
      * If iterations value is 0, is like worker will never die
      */
     $alive = 0 == $iterations;
     /**
      * Executes GearmanWorker with all jobs defined
      */
     while ($gearmanWorker->work()) {
         $iterations--;
         $event = new GearmanWorkExecutedEvent($jobs, $iterations, $gearmanWorker->returnCode());
         $this->eventDispatcher->dispatch(GearmanEvents::GEARMAN_WORK_EXECUTED, $event);
         if ($gearmanWorker->returnCode() != GEARMAN_SUCCESS) {
             break;
         }
         /**
          * Only finishes its execution if alive is false and iterations
          * arrives to 0
          */
         if (!$alive && $iterations <= 0) {
             break;
         }
     }
 }
开发者ID:dunglas,项目名称:GearmanBundle,代码行数:47,代码来源:GearmanExecute.php


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