本文整理汇总了PHP中GearmanClient::doNormal方法的典型用法代码示例。如果您正苦于以下问题:PHP GearmanClient::doNormal方法的具体用法?PHP GearmanClient::doNormal怎么用?PHP GearmanClient::doNormal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GearmanClient
的用法示例。
在下文中一共展示了GearmanClient::doNormal方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start
public static function start()
{
$gmc = new \GearmanClient();
$gmc->addServer("127.0.0.1", 4730);
$data = array();
$task = $gmc->doNormal("hunt_postman", "foo");
}
示例2: actionStart
/**
* Smpp search all
* @param $startPage Start page number
*/
public function actionStart($startPage = 1)
{
$gmanClient = new \GearmanClient();
$gmanClient->addServer($this->module->gman_server);
$httpClient = new \GuzzleHttp\Client(['base_uri' => 'http://www.smpp.go.kr']);
$res = $httpClient->request('POST', '/cop/registcorp/selectRegistCorpListVw.do', ['form_params' => ['pageIndex' => $startPage, 'pageUnit' => '100']]);
$body = $res->getBody();
$html = (string) $body;
$p = '#<a.*btnMove last.*fn_getList\\((?<lastpage>\\d+)\\);#';
if (!preg_match($p, $html, $m)) {
return;
}
$lastPage = $m['lastpage'];
echo "총 페이지수 : {$lastPage}", PHP_EOL;
for ($i = $startPage; $i <= $lastPage; $i++) {
if ($i > $startPage) {
$res = $httpClient->request('POST', '/cop/registcorp/selectRegistCorpListVw.do', ['form_params' => ['pageIndex' => $i, 'pageUnit' => '100']]);
$body = $res->getBody();
$html = (string) $body;
}
$this->parseList($html, function ($data) use($gmanClient, $i) {
echo "page({$i}) >> " . join(',', $data), PHP_EOL;
$gmanClient->doNormal('smpp_corp_get', Json::encode(['bizno' => $data['bizno']]));
});
sleep(1);
}
}
示例3: check
public function check()
{
if (class_exists('\\GearmanClient')) {
$client = new \GearmanClient();
$client->setTimeout($this->timeout);
$client->addServer($this->host, $this->port);
$mtime = microtime(true);
$result = $client->doNormal($this->functionName, json_encode(array('monitor' => 'uptize')));
if ($client->returnCode() == \GEARMAN_SUCCESS) {
$mtime = microtime(true) - $mtime;
return new Result(true, array('time' => $mtime));
}
return new Result(false, array(), $client->error());
}
return new Result(false, array(), 'Class GearmanClient not found');
}
示例4: save
function save($currpass, $newpass)
{
if (extension_loaded('gearman')) {
$rcmail = rcmail::get_instance();
$user = $_SESSION['username'];
$payload = array('username' => $user, 'oldPassword' => $currpass, 'newPassword' => $newpass);
$gmc = new GearmanClient();
$gmc->addServer($rcmail->config->get('password_gearman_host'));
$result = $gmc->doNormal('setPassword', json_encode($payload));
$success = json_decode($result);
if ($success && $success->result == 1) {
return PASSWORD_SUCCESS;
} else {
rcube::raise_error(array('code' => 600, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Password plugin: Gearman authentication failed for user {$user}: {$error}"), true, false);
}
} else {
rcube::raise_error(array('code' => 600, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Password plugin: PECL Gearman module not loaded"), true, false);
}
return PASSWORD_ERROR;
}
示例5: file_get_contents
<?php
/**
* Example of relieving CPU on the web server by using a foreground Gearman
* job, but negatively affecting performance due to having only a single
* worker.
*
* ab -n 10000 -c 250 "http://192.168.133.71/demo/3.php"
*
* Note: Be sure to run "sudo service gearman-job-server restart && php /vagrant/src/worker.php" on the worker VM.
*/
require __DIR__ . '/../../src/util.php';
echo file_get_contents(__DIR__ . '/bootstrap.html');
$client = new \GearmanClient();
$client->addServer('192.168.133.72', 4730);
$client->doNormal('expensive', sprintf('{"hogtime": %d}', rand(1, 3)));
示例6: do_worker_action
/**
* 执行Worker指定的Action
* @param host gearman服务地址
* @param port gearman端口
* @param app 应用ID
* @param ctl 控制器ID
* @param act Action
* @param param Action参数
* @param sync 是否同步
* @return mix
*/
function do_worker_action($host = '', $port = 0, $app = '', $ctl = '', $act = '', $param = array(), $sync = false, $reg_func = 'action')
{
if (empty($host)) {
$host = '127.0.0.1';
}
if (!$port) {
$port = 4730;
}
$job = new GearmanClient();
$job->addServer($host, $port);
$data['act'] = $act;
$data['ctl'] = $ctl;
$data['app'] = $app;
$data['param'] = $param;
if ($sync) {
return json_decode($job->doNormal($reg_func, json_encode($data)), true);
} else {
$job->doBackground($reg_func, json_encode($data));
}
}
示例7: sendParams
public function sendParams($newPass)
{
try {
$gmclient = new GearmanClient();
$gmclient->addServer(GEARMAN_SERVER, GEARMAN_PORT);
$payload = serialize(array('contextid' => $this->inputs['cid'], 'userid' => $this->inputs['userid'], 'newpassword' => $newPass));
$gmclient->doNormal(CHANGE_PASSWORD_FUNCTION, $payload);
if ($gmclient->returnCode() == GEARMAN_SUCCESS) {
$this->logMessage = sprintf("[INFO] Change password for uid: %s within context: %s succeeded.", $this->inputs['username'], $this->inputs['cid']);
$this->logToFile($this->logMessage);
exit(0);
} else {
if ($gmclient->returnCode() == GEARMAN_COULD_NOT_CONNECT) {
$this->logMessage = sprintf("[ERROR] Could not connect to Gearman Server with IP : %s:%s", GEARMAN_SERVER, GEARMAN_PORT);
$this->logToFile($this->logMessage);
exit(1);
} else {
$this->logMessage = sprintf("[ERROR] Gearman Server error, error code: %s", $gmclient->returnCode());
$this->logToFile($this->logMessage);
exit(1);
}
}
} catch (GearmanException $e) {
print_r($e->getMessage() . PHP_EOL);
exit(1);
}
}
示例8: GearmanClient
<?php
echo "Starting\n";
# Create our client object.
$gmclient = new GearmanClient();
# Add default server (localhost).
$gmclient->addServer();
echo "Sending job\n";
$result = $gmclient->doNormal("reverse", "TimTim is now Diptansu!");
echo "Success: {$result}\n";
示例9: GearmanClient
<?php
/**
* Run the reverse function.
*
* @link http://de2.php.net/manual/en/gearman.examples-reverse.php
*/
$gmclient = new GearmanClient();
# Add default server (localhost).
$gmclient->addServer();
$function = "reverse_string";
$data = 'Hello!';
do {
$result = $gmclient->doNormal($function, $data);
switch ($gmclient->returnCode()) {
case GEARMAN_WORK_DATA:
echo "Data: {$result}\n";
break;
case GEARMAN_WORK_STATUS:
list($numerator, $denominator) = $gmclient->doStatus();
echo "Status: {$numerator}/{$denominator} complete\n";
break;
case GEARMAN_WORK_FAIL:
echo "Failed\n";
exit;
case GEARMAN_SUCCESS:
echo "result : {$result} \n";
break;
default:
echo "RET: " . $gmclient->returnCode() . "\n";
exit;
示例10: error
<?php
if (empty($_REQUEST['city'])) {
error('city is a required parameter');
exit;
}
$gearman = new \GearmanClient();
$gearman->addServer("gearmand", "4730");
$gearman->setTimeout(1 * 500000);
$temp = $gearman->doNormal('getTemp', json_encode(array('city' => $_REQUEST['city'])));
if (!$temp) {
error($gearman->error());
} else {
jsonify(array('temp' => $temp));
}
function error($message)
{
jsonify(array('error' => $message), 500);
}
function jsonify($params, $status = 200)
{
header(' ', true, $status);
header('Content-Type: application/json');
print json_encode($params);
}
示例11: GearmanClient
<?php
// This is an example of how to submit a job to Gearman for background
// processing. It's not specific to GearmanWorkerExample, but it does use the
// functions that example registers. Run this *after* starting the worker.
$client = new GearmanClient();
$client->addServer();
echo "Sending a 'flip_it' job to gearman...\n";
echo "Returned: ";
echo $client->doNormal("flip_it", "Hello World!");
echo "\n";
echo "Sending a 'my_uppercase' job to gearman...\n";
echo "Returned: ";
echo $client->doNormal('my_uppercase', 'some lowercase string');
echo "\n";