コード例 #1
0
ファイル: Distribute.php プロジェクト: tempbottle/Charme
 public static function start()
 {
     $gmc = new \GearmanClient();
     $gmc->addServer("127.0.0.1", 4730);
     $data = array();
     $task = $gmc->doNormal("hunt_postman", "foo");
 }
コード例 #2
0
 /**
  * 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
0
 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
0
ファイル: gearman.php プロジェクト: rcg2015/roundcubemail
 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
0
ファイル: 3.php プロジェクト: michaelmoussa/talks
<?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
0
/**
 * 执行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
0
ファイル: changepwd.php プロジェクト: fica990/jsonapi
 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
0
ファイル: reverse.php プロジェクト: rjha/sc
<?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
0
ファイル: reverse.php プロジェクト: rjha/sc
<?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
0
ファイル: temp.php プロジェクト: ecliptik/formstack
<?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
0
<?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";