示例#1
0
function CreateNewClient()
{
    $_client = new GearmanClient();
    $_client->addServer("192.168.201.12");
    $_client->setCompleteCallback("jobEcho");
    return $_client;
}
示例#2
0
 /**
  * 
  * @return \Api_Component_JobServer
  */
 static function createJobServer()
 {
     $gearmanHost = new GearmanHost('localhost');
     $gearmanClient = new GearmanClient();
     $gearmanClient->addServer();
     return new Api_Component_JobServer($gearmanHost, $gearmanClient);
 }
示例#3
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);
     }
 }
示例#4
0
 public function client()
 {
     $config = $this->config->item('base_config');
     $host = $config['gearman']['host'];
     $port = $config['gearman']['port'];
     $client = new GearmanClient();
     $client->addServer($host, $port);
     $data = array('method' => 'get', 'url' => 'http://master.500mi.com/main/gearman/test', 'params' => array('wd' => '哈哈'));
     $job_handle = $client->doBackground("send_request", json_encode($data));
     if ($client->returnCode() != GEARMAN_SUCCESS) {
         echo "bad return code\n";
         exit;
     }
     $done = false;
     do {
         sleep(1);
         $stat = $client->jobStatus($job_handle);
         var_dump($stat);
         if (!$stat[0]) {
             $done = true;
         }
         echo "Running: " . ($stat[1] ? "true" : "false") . ", numerator: " . $stat[2] . ", denomintor: " . $stat[3] . "\n";
     } while (!$done);
     echo "done!\n";
 }
示例#5
0
 public static function start()
 {
     $gmc = new \GearmanClient();
     $gmc->addServer("127.0.0.1", 4730);
     $data = array();
     $task = $gmc->doNormal("hunt_postman", "foo");
 }
 public function addServer($host, $port)
 {
     $start = microtime(true);
     $result = $this->client->addServer($host, $port);
     $this->logCall($start, 'addServer', array($host, $port), $result);
     return $result;
 }
示例#7
0
 /**
  * 获取gearmant客户端
  * @return \GearmanClient
  */
 private function getClient()
 {
     if ($this->client !== null) {
         return $this->client;
     }
     $client = new \GearmanClient();
     $conStrings = array();
     foreach ($this->servers as $ser) {
         if (is_string($ser)) {
             $conStrings[] = $ser;
         } else {
             $conStrings[] = $ser['host'] . (isset($ser['port']) ? ':' . $ser['port'] : '');
         }
     }
     $conString = false;
     if (count($conStrings) > 0) {
         $conString = implode(',', $conStrings);
     }
     if ($conString) {
         $result = $client->addServers($conString);
         if ($result) {
             $this->echoTraceLog('服务器添加成功! servers: ' . $conString);
         } else {
             $this->echoErrorLog('服务器添加失败! servers: ' . $conString);
             return false;
         }
     }
     $this->client = $client;
     return $this->client;
 }
示例#8
0
 /**
  * 实现单例模式
  *
  * @param   array   $config
  * @return  GearmanClient
  */
 public static function getClient($config)
 {
     $worker = new GearmanClient();
     foreach ($config as $serverInfo) {
         $worker->addServer($serverInfo['host'], $serverInfo['port']);
     }
     return $worker;
 }
 public function __construct(\GearmanClient $client = null)
 {
     if (is_null($client)) {
         $client = new \GearmanClient();
         $client->addServers("localhost:4730");
     }
     $this->client = $client;
 }
 public function Run()
 {
     /* create our object */
     $gmclient = new \GearmanClient();
     /* add the default server */
     $gmclient->addServer();
     /* run reverse client */
     $job_handle = $gmclient->doBackground("reverse", "this is a test");
 }
示例#11
0
文件: job.class.php 项目: badtux/pmg
 public static function addJob($id, $function, $data)
 {
     $client = new \GearmanClient();
     $client->addServer(gearman_server, gearman_port);
     $job = new Job();
     $job->setId($id)->setExpireTime(time() + 172800)->setReference(array('CLIController', $function, $data));
     $job_handle = $client->doBackground(app_name . 'handle', serialize($job));
     Log::write(__METHOD__ . ' invoked gearman job (' . $function . ') for id ' . $id . ' ' . app_name . 'handle' . ' ' . $client->returnCode());
 }
示例#12
0
/**
 * This function will take 3 arguments and pass it to gearman worker to store in database
*/
function queueAssignment($name, $email, $phone)
{
    $detailsArray = array('name' => $name, 'email' => $email, 'phone' => $phone);
    $detailsStr = json_encode($detailsArray);
    writeFile($detailsArray);
    // client code
    $client = new GearmanClient();
    $client->addServer();
    $store = $client->do("saveRecord", $detailsStr);
}
 /**
  * do driver instance init
  */
 public function setup()
 {
     $settings = $this->getSettings();
     if (empty($settings)) {
         throw new BoxRouteInstanceException('init driver instance failed: empty settings');
     }
     $curInst = new \GearmanClient();
     $curInst->addServers($settings['gearmanHosts']);
     $this->instance = $curInst;
     $this->isAvailable = $this->instance ? true : false;
 }
示例#14
0
文件: Client.php 项目: knatorski/SMS
 /**
  * Ustawienie gearman klienta
  */
 protected function _setupGearmanClient()
 {
     $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
     foreach ($config->gearman->client->server as $serverAddress) {
         try {
             self::$_client->addServer($serverAddress);
         } catch (Exception $exc) {
             throw new Exception("Gearman server on {$serverAddress} is not working!");
         }
     }
 }
 protected function handleTasks()
 {
     $this->client->runTasks();
     $this->logger->debug("Client finished.");
     $this->logger->debug("Start tasks inspection.");
     $this->inspectionDto = $this->tasksInspector->inspect();
     $this->logger->debug($this->inspectionDto->getInspectionMessage());
     $this->logger->notice("Inspection message: " . serialize($this->inspectionDto->getInspectionMessage()));
     $this->handleInspection();
     return null;
 }
示例#16
0
 /**
  * This method will instantiate the object, configure it and return it
  *
  * @return Zend_Cache_Manager
  */
 public static function getInstance()
 {
     $config = App_DI_Container::get('ConfigObject');
     $gearmanClient = new GearmanClient();
     if (!empty($config->gearman->servers)) {
         $gearmanClient->addServers($config->gearman->servers->toArray());
     } else {
         $gearmanClient->addServer();
     }
     return $gearmanClient;
 }
示例#17
0
文件: Gearman.php 项目: nbari/DALMP
 /**
  * enqueue
  *
  * @param string $value
  * @return boolean
  */
 public function enqueue($value)
 {
     $gm = new \GearmanClient();
     $gm->addServer($this->host, $this->port);
     $gm->queue_name = $this->queue_name;
     if ($gm->ping('ping')) {
         $job_handle = $gmclient->doBackground($this->queue_name, json_encode($value), md5($value));
         return $this->gmclient->returnCode() != GEARMAN_SUCCESS ? false : true;
     } else {
         return false;
     }
 }
示例#18
0
 public static function singleton()
 {
     if (is_null(self::$_instance)) {
         register_shutdown_function(array("\\Pool\\Client", shutdown));
         $client = new \GearmanClient();
         foreach (\PoolConf::$SERVERS as $server) {
             $client->addServer($server[0], $server[1]);
         }
         self::$_instance = new Client($client);
     }
     return self::$_instance;
 }
示例#19
0
 public function run($task)
 {
     $client = new GearmanClient();
     $client->addServers($task["server"]);
     $client->doBackground($task["cmd"], $task["ext"]);
     if (($code = $client->returnCode()) != GEARMAN_SUCCESS) {
         Main::log_write("Gearman:" . $task["cmd"] . " to " . $task["server"] . " error,code=" . $code);
         exit;
     }
     Main::log_write("Gearman:" . $task["cmd"] . " to " . $task["server"] . " success,code=" . $code);
     exit;
 }
 public function createBackgroundProcess($functionName, $workload)
 {
     // client
     $client = new \GearmanClient();
     $client->addServer('127.0.0.1', 4730);
     $result = $client->doBackground($functionName, $workload);
     $this->isWorkerExist($functionName);
     // worker
     $this->worker = new \GearmanWorker();
     $this->worker->addServer('127.0.0.1', 4730);
     $this->worker->setTimeout(240000);
     return $this;
 }
示例#21
0
 public static function send_gearman($toAddresses, $subject, $content)
 {
     if (class_exists('GearmanClient', false)) {
         $conf = (require 'conf.php');
         $confGearman = $conf['gearman'];
         $client = new GearmanClient();
         $client->addServer($confGearman['host'], $confGearman['port']);
         $data = array('toAddresses' => $toAddresses, 'subject' => $subject, 'content' => $content);
         return $client->doBackground("send_mail", serialize($data));
     } else {
         return Mail::send($toAddresses, $subject, $content);
     }
 }
示例#22
0
 /**
  * Get GearmanClient
  *
  * @return \GearmanClient
  */
 public function getGearmanClient()
 {
     if (!$this->client) {
         $this->client = new \GearmanClient();
     }
     if ($this->timeout !== null) {
         $this->client->setTimeout($this->timeout);
     }
     if ($this->context !== null) {
         $this->client->setContext($this->context);
     }
     return $this->client;
 }
示例#23
0
	/**
	 * Divides the passed workload and handles the division of workload between
	 * multiple instances
	 */
	public function before()
	{
		// If original request and above the workable limit then we
		//  look to parallelise the work

		$m_target = $this->request->post($this->_key_name);

		if
		(
			$this->request->is_initial()
			AND isset($m_target)
			AND is_array($m_target)
			AND count($m_target) >= $this->_workable_limit
		)
		{
			// Instantiate gearman client
			$obj_gearman = new GearmanClient;
			$obj_gearman->addServer();

			// Divide the work into $this->_worker_count chunks for processing
			$int_chunk_size = round( count($m_target) / $this->_worker_count );

			$arr_chunks = array_chunk( $m_target, $int_chunk_size );

			// Reverse the route..
			$str_route = $this->request->uri();

			// Update the controller action to our own nullifier
			$this->request->action('nullifier');

			// Schedule each of the requests
			$c = 0;
			foreach ($arr_chunks as $chunk) {

				// Format the string to be passed to the worker by formatting the post
				$arr_d = $_POST;
				$arr_d[$this->_key_name] = $arr_chunks[$c];

				$str_data = $str_route . "#" . http_build_query($arr_d);

				$obj_gearman->addTask('make_request', $str_data);
				$c++;
			}

			// Set the complete requests callback
			$obj_gearman->setCompleteCallback(array($this,"complete"));

			// Execute the requests
			$obj_gearman->runTasks();
		}
	}
 public function put($queueName, $workload)
 {
     if (null === $this->client) {
         $this->client = new \GearmanClient();
         foreach ($this->servers as $server) {
             $this->client->addServer($server);
         }
     }
     $workload = serialize($workload);
     $this->client->doBackground($queueName, $workload);
     if ($this->client->returnCode() != GEARMAN_SUCCESS) {
         throw new \RuntimeException($this->client->error());
     }
 }
 /**
  * Get the GearmanClient instance
  * 
  * @return GearmanClient
  */
 public function getClientConnection()
 {
     //we have a stored connection
     if (!$this->_gmClient) {
         //Get the config, start the client object
         $_config = $this->_getConfiguration();
         $this->_gmClient = new GearmanClient();
         //add the servers to the client
         foreach ($_config as $_server) {
             $this->_gmClient->addServer($_server['host'], $_server['port']);
         }
     }
     return $this->_gmClient;
 }
 /**
  * Assign all GearmanClient callbacks as Symfony2 events
  *
  * @param \GearmanClient $gearmanClient Gearman client
  *
  * @return GearmanCallbacksDispatcher self Object
  */
 public function assignTaskCallbacks(\GearmanClient $gearmanClient)
 {
     $gearmanClient->setCompleteCallback(array($this, 'assignCompleteCallback'));
     $gearmanClient->setFailCallback(array($this, 'assignFailCallback'));
     $gearmanClient->setDataCallback(array($this, 'assignDataCallback'));
     $gearmanClient->setCreatedCallback(array($this, 'assignCreatedCallback'));
     $gearmanClient->setExceptionCallback(array($this, 'assignExceptionCallback'));
     $gearmanClient->setStatusCallback(array($this, 'assignStatusCallback'));
     $gearmanClient->setWarningCallback(array($this, 'assignWarningCallback'));
     $gearmanClient->setWorkloadCallback(array($this, 'assignWorkloadCallback'));
 }
 private function addTasks()
 {
     static $unique = 0;
     $tasksToAdd = $this->maxTasks - count($this->tasks);
     for ($i = 0; $i < $tasksToAdd; $i++) {
         $workload = call_user_func($this->workloadCallback);
         if ($workload === false) {
             return false;
         }
         $task = $this->gc->addTask($this->functionName, (string) $workload, null, $unique);
         $this->tasks[$unique] = $task;
         $unique++;
     }
     return $tasksToAdd;
 }
示例#28
0
 /**
  * 获取客户端连接
  * @return bool|\GearmanClient
  */
 private function getClient()
 {
     if ($this->client != null) {
         return $this->client;
     }
     $client = new \GearmanClient();
     $conString = $this->conString;
     $result = $client->addServers($conString);
     if (!$result) {
         $this->logError('服务器添加失败! servers: ' . $conString);
         return false;
     }
     $this->client = $client;
     return $this->client;
 }
示例#29
0
function new_fork($type, $number_operations, $data, $account_code)
{
    global $mysqli;
    $fork_encrypt_key = md5('huls0fjhslsshskslgjbtqcwijnbxhl2391');
    $token = substr(str_shuffle(md5(time()) . rand() . str_shuffle('qwertyuiopasdfghjjklmnbvcxzQWERTYUIOPKJHGFDSAZXCVBNM1234567890')), 0, 64);
    $sql = sprintf("insert into `Fork Dimension`  (`Fork Process Data`,`Fork Token`,`Fork Type`,`Fork Operations Total Operations`) values (%s,%s,%s,%d)  ", prepare_mysql(json_encode($data)), prepare_mysql($token), prepare_mysql($type), $number_operations);
    $salt = md5(rand());
    $mysqli->query($sql);
    $fork_key = $mysqli->insert_id;
    $fork_metadata = base64_encode(AESEncryptCtr(json_encode(array('code' => addslashes($account_code), 'token' => $token, 'fork_key' => $fork_key, 'salt' => $salt)), $fork_encrypt_key, 256));
    $client = new GearmanClient();
    $client->addServer('127.0.0.1');
    $msg = $client->doBackground($type, $fork_metadata);
    return array($fork_key, $msg);
}
示例#30
0
 public function init()
 {
     $this->client = new \GearmanClient();
     $this->worker = new \GearmanWorker();
     if (empty($this->servers)) {
         $this->servers = ['127.0.0.1:4730'];
     }
     $this->client->addServers(implode(',', $this->servers));
     $this->worker->addServers(implode(',', $this->servers));
     if (!empty($this->clientOptions)) {
         $this->client->setOptions(implode(' | ', $this->clientOptions));
     }
     if (!empty($this->workerOptions)) {
         $this->worker->setOptions(implode(' | ', $this->workerOptions));
     }
 }