本文整理汇总了PHP中GearmanWorker类的典型用法代码示例。如果您正苦于以下问题:PHP GearmanWorker类的具体用法?PHP GearmanWorker怎么用?PHP GearmanWorker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GearmanWorker类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: actionIndex
/**
* Runs gearman worker for mkpur
*/
public function actionIndex()
{
ini_set('memory_limit', '128M');
echo '[database connection]', PHP_EOL;
echo ' biddb : ' . $this->module->biddb->dsn, PHP_EOL;
echo ' infodb : ' . $this->module->infodb->dsn, PHP_EOL;
echo '[gearman worker]', PHP_EOL;
echo ' server : ' . $this->module->gman_server, PHP_EOL;
echo ' function : "mkpur_work"', PHP_EOL;
echo 'start worker...', PHP_EOL;
$worker = new \GearmanWorker();
$worker->addServers($this->module->gman_server);
$worker->addFunction('mkpur_work', [$this, 'mkpur_work']);
while ($worker->work()) {
}
}
开发者ID:didwjdgks,项目名称:yii2-mkpur,代码行数:19,代码来源:GearmanController.php
示例17: _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
示例18: actionSuc
public function actionSuc()
{
$this->i2_gman_func = 'i2_auto_suc';
$w = new \GearmanWorker();
$w->addServers($this->module->gman_server);
$w->addFunction('kepco_work_suc', function ($job) {
try {
$workload = Json::decode($job->workload());
$this->stdout2("kepco> %g[worker]%n {$workload['no']} {$workload['revision']} {$workload['name']} %g{$workload['id']}%n\n");
$cookie = $this->module->redis_get('kepco.cookie');
$token = $this->module->redis_get('kepco.token');
if (preg_match('/^\\d{10}$/', $workload['no'], $m)) {
$old_noti = substr($workload['no'], 0, 4) . '-' . substr($workload['no'], 4);
} else {
$old_noti = substr($workload['no'], 0, 3) . '-' . substr($workload['no'], 3, 2) . '-' . substr($workload['no'], 5);
}
$notinum = $workload['no'] . '-' . $workload['revision'];
$worker = new SucWorker(['id' => $workload['id'], 'cookie' => $cookie, 'token' => $token]);
$data = $worker->run();
$notinum = $data['notinum'] . '-' . $data['revision'];
list($noti, $revision) = explode('-', $notinum);
$bidkey = BidKey::find()->where("notinum like '{$noti}%' or notinum like '{$old_noti}%'")->andWhere(['whereis' => '03'])->orderBy('bidid desc')->limit(1)->one();
if ($bidkey === null) {
return;
}
if ($data['bidproc'] === null) {
return;
}
$this->stdout2(" %yNEW%n\n");
$data['notinum'] = $notinum;
$data['constnm'] = $bidkey['constnm'];
$data['bidid'] = $bidkey['bidid'];
$this->stdout2("%g > do {$this->i2_gman_func} {$data['bidid']} {$data['bidproc']}%n\n");
$this->module->gman_do($this->i2_gman_func, Json::encode($data));
} catch (\Exception $e) {
$this->stdout2("%r{$e}%n\n");
\Yii::error($e, 'kepco');
}
$this->module->db->close();
$this->stdout2(sprintf("[%s] Peak memory usage: %sMb\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,代码行数:45,代码来源:WorkController.php
示例19: 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
示例20: 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
注:本文中的GearmanWorker类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论