本文整理汇总了PHP中GearmanWorker::addServer方法的典型用法代码示例。如果您正苦于以下问题:PHP GearmanWorker::addServer方法的具体用法?PHP GearmanWorker::addServer怎么用?PHP GearmanWorker::addServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GearmanWorker
的用法示例。
在下文中一共展示了GearmanWorker::addServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
// Only use gearman implementation when WP_GEARS is defined and true
if (!defined('WP_GEARS') || !WP_GEARS) {
return false;
}
global $gearman_servers;
if (!class_exists('GearmanClient') || !class_exists('GearmanWorker')) {
return false;
}
if (defined('DOING_ASYNC') && DOING_ASYNC) {
$this->_worker = new GearmanWorker();
$this->_client = new GearmanClient();
if (empty($gearman_servers)) {
$this->_client->addServer();
return $this->_worker->addServer();
} else {
$this->_client->addServers(implode(',', $gearman_servers));
return $this->_worker->addServers(implode(',', $gearman_servers));
}
} else {
$this->_client = new GearmanClient();
if (empty($gearman_servers)) {
$this->_client->addServer();
} else {
$this->_client->addServers(implode(',', $gearman_servers));
}
// Supressing errors, because this will return true or false, depending on if we could connect & communicate
return @$this->_client->ping('test');
}
}
示例2: 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;
}
示例3: 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()) {
}
}
示例4: 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;
}
示例5: 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()) {
}
}
示例6: 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;
}
示例7: 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];
}
示例8: 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();
}
}
示例9: 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()) {
}
}
示例10: 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;
}
}
}
示例11: 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);
}
}
示例12: 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";
}
示例13: actionSendPasswordEmail
public function actionSendPasswordEmail()
{
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction("sendPasswordEmail", function (GearmanJob $job) {
$workload = json_decode($job->workload(), true);
$addresses = $workload['email'];
$id = $workload['id'];
$token = $workload['token'];
Yii::log(json_encode(array('token' => $token)), 'info');
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'union.zhantai.com';
$link = "http://{$host}/admin/login/setPassword/id/{$id}/token/{$token}";
$message = <<<EOT
<p><b>亲爱的用户您好!</b></p>
<p>这是一封铭智华通广告联盟密码设置邮件,<a target="_blank" href="{$link}">点击设置密码</a></p>
<p>如果上述文字点击无效,请把下面网页地址复制到浏览器地址栏中打开:</p>
<p><a target="_blank" href="{$link}">{$link}</a></p>
EOT;
$subject = '铭智广告联盟密码设置邮件';
return Yii::app()->mailer->send($addresses, $subject, $message);
});
while ($worker->work()) {
}
}
示例14: start_lib_worker
/**
* Starts a worker for the PECL library
*
* @param array $worker_list List of worker functions to add
* @return void
*
*/
protected function start_lib_worker($worker_list)
{
$thisWorker = new GearmanWorker();
$thisWorker->addOptions(GEARMAN_WORKER_NON_BLOCKING);
$thisWorker->setTimeout(5000);
foreach ($this->servers as $s) {
$this->log("Adding server {$s}", GearmanManager::LOG_LEVEL_WORKER_INFO);
$thisWorker->addServer($s);
}
foreach ($worker_list as $w) {
$this->log("Adding job {$w}", GearmanManager::LOG_LEVEL_WORKER_INFO);
$thisWorker->addFunction($w, array($this, "do_job"), $this);
}
$start = time();
while (!$this->stop_work) {
if (@$thisWorker->work() || $thisWorker->returnCode() == GEARMAN_IO_WAIT || $thisWorker->returnCode() == GEARMAN_NO_JOBS) {
if ($thisWorker->returnCode() == GEARMAN_SUCCESS) {
continue;
}
if (!@$thisWorker->wait()) {
if ($thisWorker->returnCode() == GEARMAN_NO_ACTIVE_FDS) {
sleep(5);
}
}
}
/**
* Check the running time of the current child. If it has
* been too long, stop working.
*/
if ($this->max_run_time > 0 && time() - $start > $this->max_run_time) {
$this->log("Been running too long, exiting", GearmanManager::LOG_LEVEL_WORKER_INFO);
$this->stop_work = true;
}
}
$thisWorker->unregisterAll();
}
示例15: action_index
public function action_index()
{
// Purge and terminate ob
while (ob_get_level()) ob_end_flush();
# Create our worker object.
$gearman_mworker= new GearmanWorker;
# Add default server (localhost).
$gearman_mworker->addServer();
# Register function "reverse" with the server. Change the worker function to
# "reverse_fn_fast" for a faster worker with no output.
$gearman_mworker->addFunction("make_request", array($this, "worker"));
while($gearman_mworker->work())
{
if ($gearman_mworker->returnCode() != GEARMAN_SUCCESS)
{
echo "return_code: " . $gearman_mworker->returnCode() . "\n";
break;
}
}
}