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