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


PHP GearmanWorker::addFunction方法代码示例

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


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

 public function work()
 {
     $this->_worker->addFunction($this->gearman_function(), array($this, 'do_job'));
     $this->_worker->work();
     // Killing after one job, so we don't run into unexpected behaviors or memory issues. Supervisord will respawn the php processes
     die;
 }
开发者ID:10up,项目名称:wp-gears,代码行数:7,代码来源:class-gearman-async-task.php

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

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

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

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

示例7: actionIndex

 public function actionIndex()
 {
     $w = new \GearmanWorker();
     $w->addServers($this->module->gman_server);
     $w->addFunction('kepco_file_download', function ($job) {
         $workload = Json::decode($job->workload());
         $bidid = $workload['bidid'];
         $attchd_lnk = $workload['attchd_lnk'];
         $this->stdout("한전파일> {$bidid} \n", Console::FG_GREEN);
         try {
             $saveDir = "/home/info21c/data/kepco/" . substr($bidid, 0, 4) . "/{$bidid}";
             @mkdir($saveDir, 0777, true);
             $cookie = $this->module->redis_get('kepco.cookie');
             $token = $this->module->redis_get('kepco.token');
             $downinfo = explode('|', $attchd_lnk);
             foreach ($downinfo as $info) {
                 $this->stdout(" > {$info}\n");
                 list($name, $url) = explode('#', $info);
                 $savePath = $saveDir . '/' . $name;
                 $cmd = "wget -q -T 30 --header 'Cookie: {$cookie}' --header \"X-CSRF-TOKEN: {$token}\"  --header 'Accept-Encoding: gzip' -O - '{$url}' | gunzip > \"{$savePath}\"";
                 //echo $cmd,PHP_EOL;
                 $res = exec($cmd);
             }
             $this->gman_fileconv->doBackground('fileconv', $bidid);
         } catch (\Exception $e) {
             $this->stdout("{$e}\n", Console::FG_RED);
             \Yii::error($e, 'kepco');
         }
         $this->stdout(sprintf("[%s] Peak memory usage: %s Mb\n", date('Y-m-d H:i:s'), memory_get_peak_usage(true) / 1024 / 1024), Console::FG_GREY);
         sleep(1);
     });
     while ($w->work()) {
     }
 }
开发者ID:didwjdgks,项目名称:yii2-kepco,代码行数:34,代码来源:AttchdController.php

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

示例9: register

 /**
  * @param string $function function name
  * @param callable $callback callable function function($data, \GearmanJob $job)
  * @return bool
  */
 public function register($function, callable $callback)
 {
     return $this->worker->addFunction($function, function (\GearmanJob $job) use($callback) {
         $result = Json::decode($job->workload());
         return $callback($result['data'], $job);
     });
 }
开发者ID:vaseninm,项目名称:yii2-gearman,代码行数:12,代码来源:GearmanComponent.php

示例10: actionSuc

 public function actionSuc()
 {
     $worker = new \GearmanWorker();
     $worker->addServers($this->module->gman_server);
     $worker->addFunction('ebidlh_suc_work', [SucWorker::className(), 'work']);
     while ($worker->work()) {
     }
 }
开发者ID:didwjdgks,项目名称:yii2-ebid-lh,代码行数:8,代码来源:WorkController.php

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

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

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

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

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


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