Example #1
0
 /**
  * 从所有队列接收消息
  *
  */
 public static function receive_all($force = false)
 {
     //需要强制执行超时回调者
     $forceCalls = array();
     foreach (self::$queues as $queue => $forceTime) {
         if ($forceTime) {
             $forceCalls[$queue] = 0;
         }
     }
     $queues = array_keys(self::$queues);
     $start_time = time();
     if ($force) {
         self::$waittime = 1;
     }
     while (true) {
         //			Com_Db::ping();
         Com_Db::factory('game')->clear_trans();
         //	echo "get ".var_export($queues,true)." queues | wailt ".self::$waittime."\r\n";
         $return = Com_AdCache::factory(self::$group)->brPop($queues, self::$waittime);
         if (empty($return)) {
             if ($force) {
                 break;
             }
             if (empty($forceCalls)) {
                 continue;
             } else {
                 $exec_time = time();
                 $run_time = $exec_time - $start_time;
                 $start_time = $exec_time;
                 foreach ($forceCalls as $queue => $forceTime) {
                     $forceCalls[$queue] += $run_time;
                     echo "{$queue} now wait time {$forceCalls[$queue]}\r\n";
                     //当前无消息时 会根据次数强制回调注册方法
                     if ($forceCalls[$queue] >= self::$queues[$queue]) {
                         $forceCalls[$queue] = 0;
                         echo "force call func {$queue}\r\n";
                         call_user_func_array(self::$callBacks[$queue], array());
                         //	break;
                     }
                 }
                 continue;
             }
         }
         if (isset($forceCalls[$return[0]])) {
             $forceCalls[$return[0]] = 0;
         }
         echo "receive call func {$return[0]} time=" . date('Y-m-d H:i:s', time()) . "\r\n";
         $callstarttime = microtime(true);
         call_user_func_array(self::$callBacks[$return[0]], array($return[1]));
         echo "call func run " . (microtime(true) - $callstarttime) . "\n";
     }
 }
Example #2
0
<?php

/**
 * 异步激活玩家服务 
 * @author zhangh@uuzu.com
 * @date 2012-2-27
 */
require dirname(__FILE__) . '/../global.php';
TenYear::getInstance();
ini_set('default_socket_timeout', -1);
Com_AdCache::factory()->set_timeout(0);
$objGameInit = new Game_PlayerInit();
$objGameInit->register_active();
echo "start receive \r\n";
//开始接收
Com_Queued::waittime(60);
Com_Queued::receive_all();