本文整理汇总了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()) {
}
}
示例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()) {
}
}
示例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()) {
}
}
示例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;
}
示例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;
}
示例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;
}
示例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()) {
}
}
示例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;
}
示例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];
}
示例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();
}
}
示例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;
}
示例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()) {
}
}
示例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);
}
}
示例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;
}
示例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()) {
}
}