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


PHP GearmanWorker类代码示例

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


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

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

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

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

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

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

示例6: getWorker

 /**
  * Get the GearmanWorker object
  *
  * @return GearmanWorker
  */
 public function getWorker()
 {
     if (empty($this->_worker)) {
         $this->_worker = new GearmanWorker();
         $servers = Configure::read('Gearman.servers') ?: array('127.0.0.1:4730');
         $this->_worker->addServers(implode(',', (array) $servers));
     }
     return $this->_worker;
 }
开发者ID:lorenzo,项目名称:cakephp-gearman,代码行数:14,代码来源:GearmanWorkerTask.php

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

示例8: 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 \GearmanWorker();
     $curInst->addServers($settings['gearmanHosts']);
     $this->instance = $curInst;
     $this->isAvailable = $this->instance ? true : false;
 }
开发者ID:nickfan,项目名称:appbox,代码行数:14,代码来源:GearmanWorkerBoxRouteInstanceDriver.php

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

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

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

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

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

示例14: getGearmanWorker

 /**
  * Get GearmanWorker
  *
  * @return \GearmanWorker
  */
 public function getGearmanWorker()
 {
     if (!$this->worker) {
         $this->worker = new \GearmanWorker();
     }
     if ($this->timeout !== null) {
         $this->worker->setTimeout($this->timeout);
     }
     if ($this->functions !== null) {
         foreach ($this->functions as $f) {
             $this->register($f, array($this, 'proxify'));
         }
     }
     return $this->worker;
 }
开发者ID:jackdpeterson,项目名称:MwGearman,代码行数:20,代码来源:Pecl.php

示例15: run

 public function run()
 {
     $w = new \GearmanWorker();
     $w->addServers($this->module->gman_server);
     $w->addFunction('kepco_work_suc2', function ($job) {
         try {
             $workload = Json::decode($job->workload());
             $this->stdout("%2%kkepco> [낙찰2] {$workload['id']} {$workload['no']} {$workload['name']}%n\n");
             $cookie = $this->module->redis_get('kepco.cookie');
             $token = $this->module->redis_get('kepco.token');
             $suc = new SucWorker2(['id' => $workload['id'], 'cookie' => $cookie, 'token' => $token]);
             $data = $suc->run();
             //print_r($data);
             $this->stdout(" > 공고번호 : {$data['notinum']}\n");
             $this->stdout(" > 예정가격 : {$data['yega']}\n");
             //$this->stdout(" > 복수예가 : {$data['multispare']}\n");
             $this->stdout(" > 1순위 : {$data['officenm1']}\n");
             $this->stdout(" > 참여수 : {$data['innum']}\n");
             $this->stdout(" > 진행상태 : {$data['bidproc']}\n");
             if (strlen($data['notinum']) < 10) {
                 return;
             }
             list($notino, $revno) = explode('-', $data['notinum']);
             if (preg_match('/^\\d{10}$/', $notino, $m)) {
                 $old_noti = substr($notino, 0, 4) . '-' . substr($notino, 4);
             } else {
                 $old_noti = substr($notino, 0, 3) . '-' . substr($notino, 3, 2) . '-' . substr($notino, 5);
             }
             $query = BidKey::find()->where(['whereis' => '03']);
             $query->andWhere("notinum like '{$old_noti}%' or notinum like '{$notino}%'");
             $bidkey = $query->orderBy('bidid desc')->limit(1)->one();
             if ($bidkey === null) {
                 return;
             }
             $data['bidid'] = $bidkey->bidid;
             $this->stdout(" > 개찰정보 저장 : {$bidkey->notinum} {$bidkey->constnm} ({$bidkey->state} {$bidkey->bidproc})\n");
             $this->module->gman_do('i2_auto_suc', Json::encode($data));
         } catch (\Exception $e) {
             $this->stdout("%r{$e}%n\n");
             \Yii::error($e, 'kepco');
         }
         $this->module->db->close();
         $this->memory_usage();
         sleep(1);
     });
     while ($w->work()) {
     }
 }
开发者ID:didwjdgks,项目名称:yii2-kepco,代码行数:48,代码来源:Suc2WorkAction.php


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