Exemplo n.º 1
0
 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());
     }
 }
Exemplo n.º 2
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";
 }
Exemplo n.º 3
0
 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");
 }
Exemplo n.º 4
0
 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());
 }
Exemplo n.º 5
0
 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;
     }
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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);
     }
 }
 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;
 }
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
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);
            }
        }
    }
}
Exemplo n.º 12
0
 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));
             }
         }
     }
 }
Exemplo n.º 13
0
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);
        }
    }
}
Exemplo n.º 14
0
 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;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
 function async_process_pending_monitor()
 {
     //add the gearman client stuff
     $gm = new GearmanClient();
     $gm->addServer();
     //as it is local server
     $res = $gm->doBackground('process_pending_monitor', '');
     if (!$res) {
         return false;
     }
     return True;
 }
Exemplo n.º 17
0
<?php

/**
 * Example of relieving CPU on the web server by submitting Gearman
 * jobs with multiple workers, AND improving performance by doing
 * jobs asynchronously.
 *
 * ab -n 10000 -c 250 "http://192.168.133.71/demo/5.php"
 *
 * Note: Be sure to run "sudo service gearman-job-server restart && sudo supervisorctl start demo_worker:*" 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->doBackground('expensive', sprintf('{"hogtime": %d}', rand(1, 3)));
Exemplo n.º 18
0
<?php

use LemonWeb\Deployer\Exceptions\DeployException;
use LemonWeb\Deployer\Patchers\Helper;
require __DIR__ . '/../../../autoload.php';
$args = Helper::parseArgs($_SERVER['argv']);
if (!isset($args['ip'])) {
    throw new DeployException('Gearman server ip not specified');
}
if (!isset($args['port'])) {
    throw new DeployException('Gearman server port not specified');
}
if (!isset($args['function'])) {
    throw new DeployException('Gearman function name not specified');
}
// Send 'reboot' command to gearman worker.
$client = new GearmanClient();
$client->addServer($args['ip'], $args['port']);
$client->doBackground($args['function'], 'reboot');
Exemplo n.º 19
0
<?php

$client = new GearmanClient();
$client->addServer();
$job_handle = $client->doBackground("setup", 1);
var_dump($job_handle);
if ($client->returnCode() != GEARMAN_SUCCESS) {
    echo "bad return code\n";
    exit;
}
$done = false;
do {
    sleep(3);
    $stat = $client->jobStatus($job_handle);
    if (!$stat[0]) {
        // the job is known so it is not done
        $done = true;
    }
    echo "Running: " . ($stat[1] ? "true" : "false") . ", numerator: " . $stat[2] . ", denomintor: " . $stat[3] . "\n";
} while (!$done);
echo "done!\n";
Exemplo n.º 20
0
 public function CompilePHP()
 {
     $this->FuncName = preg_replace('/\\W+|php/', '', $this->Title);
     $this->Path = '/php/' . $this->FuncName;
     $client = new GearmanClient();
     $client->addServer();
     $client->doBackground('CompilePHP', $this->FuncName);
     echo "\n<p><b>Started compiling PHP {$this->Title}</b></p>\n\n";
 }
Exemplo n.º 21
0
foreach ($msg_his_arr as $key_arr) {
    $tmp_tex = "";
    foreach ($key_arr as $key) {
        if (empty($tmp_tex)) {
            $tmp_tex = $key;
        } else {
            $tmp_tex = $tmp_tex . "=" . $key;
        }
    }
    fwrite($myfile, $tmp_tex . "\r\n");
    $idx++;
    if ($idx >= 3) {
        break;
    }
}
fclose($myfile);
$myfile = fopen("./msg_res.txt", "w") or die("Unable to open file!");
$tmp_tex = "";
foreach ($msg_res_arr as $key) {
    if (empty($tmp_tex)) {
        $tmp_tex = $key;
    } else {
        $tmp_tex = $tmp_tex . "=" . $key;
    }
}
fwrite($myfile, $tmp_tex . "\r\n");
fclose($myfile);
$gmclient = new GearmanClient();
$gmclient->addServer("10.0.128.219");
$gmclient->doBackground("hotblood_pack_task", $build_par);
header("Location: ./index.php");
Exemplo n.º 22
0
<?php

$c = new GearmanClient();
$c->addServer('127.0.0.1');
$h = $c->doBackground('abc', 'abc');
//while(true)
var_dump($c->jobStatus($h));
//exit;
$w = new GearmanWorker();
$w->addServer('127.0.0.1');
var_dump($w->addFunction('abc', function () {
    echo "123\n";
}, $ctx, 0));
while (true) {
    $w->work();
}
Exemplo n.º 23
0
$input = new SplFileObject($argv[1], 'r');
$output = new SplFileObject($argv[2], 'w');
$checked = 0;
$valid = 0;
$invalid = 0;
$started = microtime(1);
$client = new GearmanClient();
$client->addServer();
$client->setCompleteCallback(function (GearmanTask $task) use(&$output, &$checked, $started, &$valid, &$invalid) {
    $data = json_decode($task->data(), true);
    if ($data['status']) {
        $output->fwrite($data['email'] . PHP_EOL);
        $valid++;
    } else {
        $invalid++;
    }
    $checked++;
    echo "\r" . date(DATE_ATOM) . " Speed: " . $checked / (microtime(1) - $started) . " emails / sec. Valid: {$valid}, Invalid: {$invalid}.                    ";
});
$client->setExceptionCallback(function (GearmanTask $task) {
    echo "Exception!\n";
});
while (!$input->eof()) {
    //    for ($i = 0; $i < 2048; $i++) {
    $client->doBackground('check_email', trim($input->fgets()));
    //    }
    //    break;
}
//$client->runTasks();
//
//$client->wait();
Exemplo n.º 24
0
 public function updateJobInfo($jobid, $status, $case)
 {
     if ($status == 2) {
         //执行完毕 提交任务
         if (preg_match("/^cloud(.*?)/i", $jobid, $tempa)) {
             //云执行任务
             $sql = " UPDATE run_cloud_jobs SET status='complete' WHERE job_id = '{$jobid}' ";
             $this->db->exec_query($sql);
             //清理环境
             $client = new GearmanClient();
             $client->addServer("localhost", 4730);
             $client->doBackground("killEnv_{$jobid}", $jobid);
         } else {
             //传统任务
             $sql = " SELECT * FROM running_jobs WHERE job_id='{$jobid}'";
             $job = $this->db->fetchFirstRow($sql);
             $sql = " INSERT INTO run_end_jobs " . " (job_id,  job_type, topo_type, job_startTime,  productline_id,  tplan_id,  build_id,  device_id,  total_case,  pass_case, olddiff_case, fail_case,  accept_case,  block_case,  na_case,  skip_case,  warn_case,  user_id,  running_vdi, runend_case) " . " VALUES ('{$job['job_id']}','{$job['job_type']}',{$job['topo_type']},'{$job['job_startTime']}','{$job['productline_id']}','{$job['tplan_id']}','{$job['build_id']}','{$job['device_id']}','{$job['total_case']}','{$job['pass_case']}','{$job['olddiff_case']}','{$job['fail_case']}','{$job['accept_case']}','{$job['block_case']}','{$job['na_case']}','{$job['skip_case']}','{$job['warn_case']}','{$job['user_id']}','{$job['running_vdi']}','{$job['runend_case']}' ) ";
             $this->db->exec_query($sql);
             $sql = " DELETE FROM running_jobs WHERE job_id = '{$job['job_id']}' ";
             $this->db->exec_query($sql);
         }
         return 'commit job success!';
     } else {
         // 刷新任务暂停、继续或刷新任务当前case
         if (preg_match("/^cloud(.*?)/i", $jobid, $tempa)) {
             // 云执行任务
             if ($status == 0) {
                 $status = 'pause';
             } elseif ($status == 1) {
                 $status = 'running';
             }
             $sql = " UPDATE run_cloud_jobs SET status = '{$status}' WHERE job_id = '{$jobid}' ";
             $rs = $this->db->exec_query($sql);
             return $rs ? 'updateJobInfo success' : 'DB ERROR';
         } else {
             //传统任务
             $run_time = "'" . date("H:i:s") . "'";
             $sql = " UPDATE running_jobs SET status = {$status} ";
             if ($case != '') {
                 $sql = $sql . ", run_time = {$run_time}, running_case = '{$case}'";
             }
             $sql = $sql . " WHERE job_id = '{$jobid}' ";
             $rs = $this->db->exec_query($sql);
             return $rs ? 'updateJobInfo success' : 'DB ERROR';
         }
     }
 }
Exemplo n.º 25
0
<?php

require_once "Job.php";
require_once "Logger.php";
$logger = new Logger();
$client = new GearmanClient();
$client->addServer();
// by default host/port will be "localhost" & 4730
foreach (new FilesystemIterator('./hd') as $filePath => $fileInfo) {
    /** @var SplFileInfo $fileInfo */
    if ($fileInfo->isFile() && $fileInfo->isReadable()) {
        $job = new Job($filePath, realpath('./converted/') . DIRECTORY_SEPARATOR . $fileInfo->getBasename('.' . $fileInfo->getExtension()), Job::$defaultResolutionList);
        $logger->sendingJob($job);
        $client->doBackground('convert', json_encode($job));
    }
}
Exemplo n.º 26
0
function Action3()
{
    $client = new GearmanClient();
    $client->addServer("115.28.54.237", 4730);
    $i = 0;
    global $db;
    $dbbooks = $db->get_books(CYSTS8::$siteid);
    foreach ($dbbooks as $bookid => $dbbook) {
        $dbchapters = $db->get_chapters(CYSTS8::$siteid, $bookid);
        foreach ($dbchapters as $chapterid => $dbchapter) {
            $uri = $dbchapter["uri"];
            $uri2 = $dbchapter["uri2"];
            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('DownloadYsts8', $workload, $workload);
        }
    }
}
Exemplo n.º 27
0
 $input_file_name = $_SERVER['argv'][1];
 $num_of_item_sleep = 1000;
 // read file
 $handle = @fopen($input_file_name, "r");
 if ($handle) {
     $i = 0;
     while (!feof($handle)) {
         $i++;
         // read with limit item pertime
         $userid = intval(fgets($handle));
         if (empty($userid)) {
             continue;
         }
         $data = array("userid" => $userid, "flag" => 1);
         $data = Zend_Json::encode($data);
         $job_handle = $client->doBackground($jobs->sync_search, $data);
         echo "Push userid = {$userid} to gearman update profile, Job handle = {$job_handle}\n";
         $data = array("userid" => $userid, "flag" => 2);
         $data = Zend_Json::encode($data);
         $job_handle = $client->doBackground($jobs->sync_search, $data);
         echo "Push userid = {$userid} to gearman update occupation, Job handle = {$job_handle}\n";
         $data = array("userid" => $userid, "flag" => 3);
         $data = Zend_Json::encode($data);
         $job_handle = $client->doBackground($jobs->sync_search, $data);
         echo "Push userid = {$userid} to gearman update knowlegde, Job handle = {$job_handle}\n";
         echo "\n";
         if ($i == $num_of_item_sleep) {
             $i = 0;
             echo "SLEEP 1/10s !!!!";
             usleep(100000);
         }
Exemplo n.º 28
0
 public function addJob($task, $data)
 {
     return $this->_gearmanClient->doBackground($task, $data);
 }
Exemplo n.º 29
0
<?php

define('CELLIO', true);
define('LIBPATH', realpath(dirname(__FILE__) . '/..') . '/lib');
require_once LIBPATH . '/init.php';
// Variables, assemble!
$time = gmdate('r');
$req = array_change_key_case($_REQUEST, CASE_UPPER);
$recipientSID = $req['ACCOUNTSID'];
$callnum_recv = $req['TO'];
$callnum_from = $req['FROM'];
$geo = gen_geo_output($req, 'pre');
$email_to = $config['ACCOUNTS'][$recipientSID]['EMAIL'];
$email_subject = 'Twilio Call From ' . $callnum_from;
$email_body = "Call received to {$callnum_recv}\n\nTime: {$time}\n\nFrom: {$callnum_from}{$geo}";
// Use either Gearman or non-asynchronous fallback
if ($config['OPTS']['USE_GEARMAN']) {
    $gmc = new GearmanClient();
    $gmc->addServers($config['OPTS']['GEARMAN_SERVERS']);
    $res = $gmc->doBackground('send_email', json_encode(array('TO' => $email_to, 'SUBJECT' => $email_subject, 'BODY' => $email_body)));
} else {
    send_email($email_to, $config['OPTS']['EMAIL_FROM'], $email_subject, $email_body);
}
// Craft voicemail request
$twiml = array(array('name' => 'Say', 'value' => $config['ACCOUNTS'][$recipientSID]['VOICEMAIL_PROMPT']), array('name' => 'Record', 'attributes' => array('action' => $config['OPTS']['URL'] . '/voicemail.php', 'timeout' => $config['OPTS']['VOICEMAIL_TIMEOUT'], 'maxLength' => $config['OPTS']['VOICEMAIL_LEN'], 'trim' => $config['OPTS']['VOICEMAIL_TRIM'], 'playBeep' => $config['OPTS']['VOICEMAIL_BEEP'])), array('name' => 'Say', 'value' => $config['OPTS']['VOICEMAIL_TIMEOUT_MSG']));
// Tell Twilio to capture a voicemail
print_TwiML($twiml);
Exemplo n.º 30
0
<?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!';
$job_handle = $gmclient->doBackground($function, $data);
if ($gmclient->returnCode() != GEARMAN_SUCCESS) {
    echo "bad return code\n";
    exit;
}
echo "done!\n";