示例#1
0
function initCounter()
{
    global $counter;
    if ($counter === null) {
        $counter = new SaeCounter();
        $counter->create('dbhit');
        $counter->create('cachehit');
        $counter->create('mailsent');
    }
}
示例#2
0
 public function counter()
 {
     $c = new SaeCounter();
     //实例化
     $c->create("test");
     //创建计算器
     $c->set("test", 30);
     //设置值
     $ret = $c->get("test");
     //获得值
     dump($ret);
     $ret = $c->incr("test");
     //增加值
     dump($ret);
     $ret = $c->decr("test");
     //减少值
     dump($ret);
 }
示例#3
0
 public function ck_addtask()
 {
     $c = new SaeCounter();
     if (!$c->exists('sae_checker_wait_tq')) {
         if (!$c->create('sae_checker_wait_tq', 0)) {
             return '1.1';
         }
     }
     $url = $_SERVER['SCRIPT_URI'] . '?passkey=' . $GLOBALS['md5key'] . '&service=taskq&action=trigger';
     $this->tq()->addTask($url, NULL, true);
     $this->tq()->push();
     $s_time = time();
     $pass = false;
     while (!$pass && time() - $s_time < 20) {
         if ($c->get('sae_checker_wait_tq') > 0) {
             $pass = true;
         } else {
             time_nanosleep(0, 100000000);
         }
         // 1/10 second
     }
     $c->remove('sae_checker_wait_tq');
     if ($pass) {
         return '1.0';
     } else {
         return '1.1';
     }
 }