本文整理汇总了PHP中GearmanClient::doBackground方法的典型用法代码示例。如果您正苦于以下问题:PHP GearmanClient::doBackground方法的具体用法?PHP GearmanClient::doBackground怎么用?PHP GearmanClient::doBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GearmanClient
的用法示例。
在下文中一共展示了GearmanClient::doBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
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());
}
}
示例2: client
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";
}
示例3: Run
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");
}
示例4: addJob
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());
}
示例5: add
public function add($hook, $args = array(), $priority = 'normal')
{
$jobdata = array();
$jobdata['hook'] = $hook;
$jobdata['args'] = $args;
$jobdata['blog_id'] = function_exists('is_multisite') && is_multisite() ? get_current_blog_id() : null;
switch ($priority) {
case 'high':
return $this->_client->doHighBackground($this->gearman_function(), json_encode($jobdata));
break;
case 'low':
return $this->_client->doLowBackground($this->gearman_function(), json_encode($jobdata));
break;
case 'normal':
default:
return $this->_client->doBackground($this->gearman_function(), json_encode($jobdata));
break;
}
}
示例6: run
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;
}
示例7: send_gearman
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);
}
}
示例8: createBackgroundProcess
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;
}
示例9: new_fork
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);
}
示例10: queueSMS
function queueSMS($msgdata)
{
if (isset($msgdata['from'])) {
$this->from = $msgdata['from'];
}
$workload['msgdata']['from'] = $this->from;
$workload['msgdata']['to'] = $msgdata['to'];
$workload['msgdata']['msg'] = $msgdata['msg'];
$workload['provider'] = get_class($this);
$workload['api_key'] = $this->api_key;
$workload['api_secret'] = $this->api_secret;
if ($this->extra != null) {
$workload['extra'] = $this->extra;
}
$client = new \GearmanClient();
$client->addServer();
$job_handle = $client->doBackground("sendSMS", json_encode($workload));
return $job_handle;
}
示例11: Action3
function Action3()
{
$client = new GearmanClient();
$client->addServer("115.28.54.237", 4730);
$i = 0;
global $db;
global $sites;
foreach ($sites as $siteid => $site) {
$dbbooks = $db->get_books($siteid);
print_r("[{$siteid}] db-book count: " . count($dbbooks) . "\n");
foreach ($dbbooks as $bookid => $dbbook) {
$dbchapters = $db->get_chapters($siteid, $bookid);
print_r("[{$siteid}] db-chapter count: " . count($dbchapters) . "\n");
foreach ($dbchapters as $chapterid => $dbchapter) {
print_r("Add task({$bookid}, {$chapterid})\n");
$workload = sprintf("%s,%d", $bookid, $chapterid);
$client->doBackground('comic-bengou', $workload, $workload);
}
}
}
}
示例12: getFiles
public static function getFiles()
{
if (!empty($_FILES)) {
foreach ($_FILES["file"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
if (!file_exists(self::$uploads_dir)) {
mkdir(self::$uploads_dir);
}
$tmp_name = $_FILES["file"]["tmp_name"][$key];
$name = $_FILES["file"]["name"][$key];
move_uploaded_file($tmp_name, self::$uploads_dir . $name);
$excel = new SimpleExcel('csv');
$excel->parser->loadFile(self::$uploads_dir . $name);
$data = $excel->parser->getField();
unset($data[0]);
$client = new GearmanClient();
$client->addServer();
$client->doBackground('q' . $key, serialize($data));
}
}
}
}
示例13: Action3
function Action3($siteid)
{
global $db;
$client = new GearmanClient();
$client->addServer("115.28.54.237", 4730);
$i = 0;
$dbbooks = $db->get_books($siteid);
foreach ($dbbooks as $bookid => $dbbook) {
$dbchapters = $db->get_chapters($siteid, $bookid);
foreach ($dbchapters as $chapterid => $dbchapter) {
$uri = $dbchapter["uri"];
$uri2 = $dbchapter["uri2"];
if (strlen($uri2) > 1 || 0 == strncmp("175.195.249.184", $uri, 10)) {
//if(strlen($uri) > 1 || strlen($uri2) > 1)
continue;
}
++$i;
print_r("[{$i}]Add task({$bookid}, {$chapterid})\n");
$workload = sprintf("%s,%d", $bookid, $chapterid);
$client->doBackground('DownloadPingshu8', $workload, $workload);
}
}
}
示例14: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/* @var $em EntityManager */
$em = $this->getContainer()->get('doctrine')->getManager();
$waktuSekarang = new \DateTime();
$perulangan = JadwalKehadiran::getDaftarPerulangan();
$workload['waktu_sekarang'] = $waktuSekarang;
$workload['paksa'] = $input->getOption('paksa');
$semuaSekolah = $em->getRepository('LanggasSisdikBundle:Sekolah')->findAll();
foreach ($semuaSekolah as $sekolah) {
if (!(is_object($sekolah) && $sekolah instanceof Sekolah)) {
continue;
}
$workload['sekolah'] = $sekolah->getId();
if (!$input->getOption('paksa')) {
$kalenderPendidikan = $em->getRepository('LanggasSisdikBundle:KalenderPendidikan')->findOneBy(['sekolah' => $sekolah, 'tanggal' => $waktuSekarang, 'kbm' => true]);
if (!(is_object($kalenderPendidikan) && $kalenderPendidikan instanceof KalenderPendidikan)) {
continue;
}
}
$mesinKehadiran = $em->getRepository('LanggasSisdikBundle:MesinKehadiran')->findBy(['sekolah' => $sekolah, 'aktif' => true]);
foreach ($perulangan as $key => $value) {
$workload['perulangan'] = $key;
$logDirectory = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . 'fingerprintlogs' . DIRECTORY_SEPARATOR . $sekolah->getId() . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . $waktuSekarang->format('Y-m-d');
if (!is_dir($logDirectory)) {
continue;
}
foreach ($mesinKehadiran as $mesin) {
if (!(is_object($mesin) && $mesin instanceof MesinKehadiran)) {
continue;
}
if ($mesin->getAlamatIp() == '') {
continue;
}
$logFiles = [];
exec("cd {$logDirectory} && ls -1t {$mesin->getAlamatIp()}*", $logFiles);
$logFile = '';
foreach ($logFiles as $logFile) {
if ($logFile == '') {
continue;
}
if (!$input->getOption('paksa')) {
$prosesLog = $em->createQueryBuilder()->select('COUNT(prosesLog.id)')->from('LanggasSisdikBundle:ProsesLogKehadiran', 'prosesLog')->where('prosesLog.sekolah = :sekolah')->andWhere('prosesLog.namaFile = :namaFile')->setParameter('sekolah', $sekolah)->setParameter('namaFile', $logFile)->getQuery()->getSingleScalarResult();
if ($prosesLog > 0) {
continue;
}
}
$workload['log_file'] = $logDirectory . DIRECTORY_SEPARATOR . $logFile;
/* @var $logger Logger */
$logger = $this->getContainer()->get('monolog.logger.attendance');
$gearman = new \GearmanClient();
$gearman->addServer();
$jobFunction = "LanggasSisdikBundleWorkerPembaruanKehadiranWorker~pembaruan";
$proses = new ProsesLogKehadiran();
$proses->setAwalProses($waktuSekarang);
$proses->setNamaFile($logFile);
$proses->setSekolah($sekolah);
$proses->setStatusAntrian('a-masuk-antrian');
$proses->setPrioritas($input->getOption('prioritas'));
$em->persist($proses);
$em->flush();
$workload['proses_log'] = $proses->getId();
switch ($input->getOption('prioritas')) {
case "tinggi":
$gearman->doHighBackground($jobFunction, serialize($workload));
$logger->addInfo($sekolah->getId() . ' | ' . $sekolah->getNama() . ' | kehadiran | prioritas-tinggi | ' . $workload['log_file']);
break;
case "normal":
$gearman->doBackground($jobFunction, serialize($workload));
$logger->addInfo($sekolah->getId() . ' | ' . $sekolah->getNama() . ' | kehadiran | prioritas-normal | ' . $workload['log_file']);
break;
case "rendah":
$gearman->doLowBackground($jobFunction, serialize($workload));
$logger->addInfo($sekolah->getId() . ' | ' . $sekolah->getNama() . ' | kehadiran | prioritas-rendah | ' . $workload['log_file']);
break;
}
}
}
}
}
}
示例15: do_background_job
function do_background_job($action, $data)
{
// 保存数据到gearman,异步执行
$gm = new GearmanClient();
foreach (explode(";", $GLOBALS['AX_GEARMAN_SERVER']) as $server) {
list($host, $port) = explode(":", $server);
$gm->addServer($host, $port);
}
@$gm->doBackground($action, $data);
if ($gm->returnCode() == GEARMAN_SUCCESS) {
return true;
}
return false;
}