當前位置: 首頁>>代碼示例>>PHP>>正文


PHP GearmanClient::doBackground方法代碼示例

本文整理匯總了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());
     }
 }
開發者ID:rcambien,項目名稱:riverline-worker-bundle,代碼行數:14,代碼來源:Gearman.php

示例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";
 }
開發者ID:sdgdsffdsfff,項目名稱:hiveAdmin,代碼行數:25,代碼來源:gearman.php

示例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");
 }
開發者ID:JasonOcean,項目名稱:iOS_Interest_Group,代碼行數:9,代碼來源:gearman_ut.php

示例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());
 }
開發者ID:badtux,項目名稱:pmg,代碼行數:9,代碼來源:job.class.php

示例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;
     }
 }
開發者ID:10up,項目名稱:wp-gears,代碼行數:19,代碼來源:class-gearman-async-task.php

示例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;
 }
開發者ID:royalwang,項目名稱:swoole-crontab,代碼行數:12,代碼來源:Gearman.class.php

示例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);
     }
 }
開發者ID:tonny-zhang,項目名稱:mailer-php,代碼行數:13,代碼來源:class.Mail.php

示例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;
 }
開發者ID:vadimizmalkov,項目名稱:visoft-base-module,代碼行數:13,代碼來源:ProcessingService.php

示例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);
}
開發者ID:inikoo,項目名稱:fact,代碼行數:15,代碼來源:fork_functions.php

示例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;
 }
開發者ID:kaalpurush,項目名稱:sms,代碼行數:19,代碼來源:SMS.php

示例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);
            }
        }
    }
}
開發者ID:guozanhua,項目名稱:bookspider,代碼行數:21,代碼來源:comic-client.php

示例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));
             }
         }
     }
 }
開發者ID:nycmic,項目名稱:csv,代碼行數:22,代碼來源:myClass.php

示例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);
        }
    }
}
開發者ID:guozanhua,項目名稱:bookspider,代碼行數:23,代碼來源:pingshu8-client.php

示例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;
                     }
                 }
             }
         }
     }
 }
開發者ID:alisyihab,項目名稱:sisdik,代碼行數:81,代碼來源:PembaruanKehadiranCommand.php

示例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;
}
開發者ID:songliang89,項目名稱:auto-xhprof,代碼行數:14,代碼來源:auto-xhprof.php


注:本文中的GearmanClient::doBackground方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。