public function receive_log($force = false) { if ($force) { $this->minUpdateTime = 0; $this->minUpdateNum = 1; } return Com_Queued::register($this->get_queue(), array($this, 'update'), $this->minUpdateTime); }
/** * 取队列 */ public function receive_data() { return Com_Queued::register($this->tencent_compass_queue, array($this, 'parae_data_and_request')); }
public function sendSysMail($dataArr, $type, $nowTime, $ip) { global $AccountArr; if (!isset($AccountArr)) { echo "not require AccountArr\n"; $filename = DATA_PATH . '/cache/ceshi_user.cache'; if (file_exists($filename)) { echo "require AccountArr\n"; require_once $filename; } else { $AccountArr = array(); } } $account = $dataArr['account']; $player_id = $dataArr['player_id']; if (!empty($AccountArr) && isset($AccountArr[SERVER_ID])) { $dataArr = $AccountArr[SERVER_ID]; if (in_array($account, $dataArr['account'])) { $mail["mail_type"] = 0; $mail["sender"] = 0; $mail["sender_name"] = Language_Error::get_language_error('ERROR_MAIL_3'); $mail["receiver"] = $player_id; $mail["title"] = $dataArr['title']; $mail["content"] = $dataArr['content']; $mail["silver"] = 0; $mail["gold"] = 0; if (!empty($dataArr['props'])) { $props = explode(';', $dataArr['props']); foreach ($props as $prop) { $propArr = explode(':', $prop); if (!isset($propArr[2])) { $propArr[2] = 0; } $mail["prop"][] = array("prop_id" => $propArr[0], "item_num" => $propArr[1], "quality" => $propArr[2]); } $mail["attachment"]["prop"] = $mail["prop"]; } $mail["attachment"] = array(); if ($mail["mail_type"] === 0) { if (isset($mail["silver"])) { if ($mail["silver"] > 0) { $mail["attachment"]["silver"] = $mail["silver"]; } unset($mail["silver"]); } if (isset($mail["gold"])) { if ($mail["gold"] > 0) { $mail["attachment"]["gold"] = $mail["gold"]; } unset($mail["gold"]); } if (isset($mail["prop"])) { if (!empty($mail["prop"])) { $mail["attachment"]["prop"] = $mail["prop"]; } unset($mail["prop"]); } if (count($mail["attachment"]) > 0) { $mail["attachment_state"] = 1; } } //file_put_contents(PROJECT_ROOT.'/uuzudo.log',var_export(array('sendMessage',$account,$op,$nowTime,$ip),true)."\n",FILE_APPEND); Com_Queued::send("mail", Com_Serialize::serialize($mail)); } } }
/** * 写日志 * @param string $content */ public function log_write($data, $type = null) { #$content['table'] = $this->_table; if (isset($data['add_time'])) { $add_time = $data['add_time']; } else { $add_time = time(); } $content['table'] = $this->get_table_name($data['channel'], $add_time, $type); $content['data'] = $data; $result = Com_Queued::send($this->get_queue(), json_encode($content)); // $result = false; if (!$result) { Com_Log::write('xgame.all.error', "Queued send error..." . json_encode($content)); $fp = $this->get_log_fp(); if ($fp) { $content = $this->create_sql($content['table'], $data); fwrite($fp, $content); } } }
/** * crontab 注册队列 */ public function register_trigger_union_guide() { return Com_Queued::register('async_update_union_guide', array($this, 'do_async_trigger_union_guide')); }
//上次domain执行时间 $damonRunTime = 0; $damonCheckLife = 30; //进程列表 $processList = array(); $processUpdateTime = 0; $processUpdateLife = 300; //每日已经启动进程LIST 避免没有启动 $redis = Com_AdCache::factory(); $dateKey = date('Y-m-d'); $processRunList = array(); $processRunList[$dateKey] = $objProcess->getRunStat($dateKey); $firstLoop = true; while (true) { $restart = false; if ($restart = Com_Queued::receive_byrpop("process")) { # 从队列process表尾获取元素,返回nil或者队列名与元素组成的数组 $processList = $objProcess->getProcessList(); foreach ($processList as $process) { if ($process['process_interval']) { continue; } if (!$mainProcess && $process['process_flag']) { continue; } if (!IS_CSBATTLE && $process['process_flag'] == 2) { continue; } Process_Server::killProcess(PROCESS_PATH . '/' . $process['process_file'], CLI_PATH); // exec("sudo -u nobody /usr/local/webserver/php/bin/php ".PROJECT_ROOT."/test/tools/MakeCacheFile.php"); // exec("sudo -u nobody /usr/local/webserver/php/bin/php ".PROJECT_ROOT."/test/tools/generate_cache.php");
/** * 从所有队列接收消息 * */ 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"; } }
/** * 异步执行 * * @param unknown_type $data * @return unknown */ protected function active_wait($data) { $data['exec'] = 1; $message = json_encode($data); return Com_Queued::send($this->init_queue, $message); }
public function register_deal_challenge_battle() { return Com_Queued::register($this->_deal_challenge_battle_channel, array($this, 'do_async_deal_challenge_battle')); }
/** * 异步回调方法 * * @param unknown_type $className 类名 * @param unknown_type $classType 类类型 game, data, 空则表示全名 * @param unknown_type $function 方法名 * @param unknown_type $params 参数数组 * @return unknown */ public static function asyn_call_func($className, $classType, $function, $params) { $call = array(); if ($classType == 'game') { $class['class'] = TenYear::game_name($className); } elseif ($classType == 'data') { $class['class'] = TenYear::data_name($className); } else { $class['class'] = $className; } $class['function'] = $function; $class['params'] = $params; return Com_Queued::send(self::$asynCallQueue, json_encode($class)); }
public function register_upgrade($channel_seq) { return Com_Queued::register($this->upgradeChannel . "_" . $channel_seq, array($this, 'player_upgrade')); }
public function register_attr($channel_seq) { return Com_Queued::register($this->_sync_player_attr . "_" . $channel_seq, array($this, 'sync')); }
/** * 队列执行回调方法 */ public function receive_data() { Com_Queued::register($this->queue_37wan_chatmonitor, array($this, 'report_msg')); }
/** * 注册队列 */ public function register_trigger_union_achieve() { return Com_Queued::register("union_achieve", array($this, 'trigger_union_achieve')); }
public function register_deal_event_log() { return Com_Queued::register($this->_deal_event_log_channel, array($this, 'do_async_deal_event_log')); }
/** * 腾讯 应用发货通知 * @param int $player_id 玩家id * @param int * @param array $arr_replace */ public function pushToTencent($data) { if (empty($data)) { return; } $data = json_decode($data, true); file_put_contents(PROJECT_ROOT . '/uuzudo.log', var_export(array('q1', $data), true) . "\n", FILE_APPEND); if (!isset($data['time'])) { return false; } $current_time = time(); $sleep_seconds = $data['time'] + $this->pushAppTime - $current_time; if ($sleep_seconds <= 0) { $player_id = $data['player_id']; $key_arr = array('openid', 'openkey', 'pf', 'pfkey'); $session_id = $this->get_data('Player')->get_player_info($player_id, 'session_id'); $session_info = $this->get_game('Online')->get_session($session_id); foreach ($key_arr as $key) { $params[$key] = $session_info[$key]; } //$params = $this->redis()->hash_get($this->user_tencent_table. ':'. $player_id, $key_arr); if (empty($params)) { printf("token_id=%s, billno=%s, zoneid=%s, payitem=%s of tencent_info empty!\n", $data['info']['token_id'], $data['info']['billno'], $data['info']['zoneid'], $data['info']['payitem']); return -1; } $params['provide_errno'] = $data['ret']; $params['ts'] = $current_time; foreach (array('payitem', 'token_id', 'billno', 'zoneid', 'amt', 'payamt_coins') as $key) { $params[$key] = $data['info'][$key]; } //向腾讯应用发请求 confirm $res = $this->api($this->pushAppConfirmApi, $params, 'post', 'https'); file_put_contents(PROJECT_ROOT . '/uuzudo.log', var_export(array('q2', $res, $params), true) . "\n", FILE_APPEND); if ($res['ret'] != 0) { $res = $this->api($this->pushAppConfirmApi, $params, 'post', 'https'); } //log $params['ret'] = $res['ret']; $params['msg'] = $res['msg']; $log_key = $this->log_key . ':' . date('Ymd', $current_time); $this->redis()->list_push($log_key, json_encode($params)); $this->redis()->expire($log_key, 86400 * 7); } else { Com_Queued::send('tencent_pay', json_encode($data)); sleep($sleep_seconds); } return true; }
/** * 从队列中接收消息 * */ public function receive_data() { return Com_Queued::register($this->dclogChannel, array($this, 'post_data')); }
<?php /** * LOG消息统一接收服务 * @author zhangh@uuzu.com * @date 2011-12-13 */ require dirname(__FILE__) . '/../global.php'; TenYear::getInstance(); ini_set('default_socket_timeout', -1); Com_AdCache::factory()->set_timeout(0); //注册LOG接收 require CRONTAB_PATH . '/Log/Update.php'; $objLog = new Log_Update(); $force = false; if ($argv[1] == 'r') { //手动 $force = true; } $objLog->receive_log($force); echo "register log receive \r\n"; echo "start receive \r\n"; //开始接收 Com_Queued::receive_all($force);
public function register_sys_clear_union_apply() { return Com_Queued::register($this->_sys_clear_union_apply, array($this, 'do_clear_union_apply')); }
public function flush_cache($dbname = "setting") { Com_Cache::factory($dbname)->flush(); Com_Cache::factory("game")->flush(); Com_Queued::send("process", "restart"); }
/** * 第四步 推送给腾讯 */ public function pushTencent($data) { $data['time'] = time(); $data['player_id'] = $this->player_id; $data['info'] = array('token_id' => $this->auth['token']); foreach (array('payitem', 'billno', 'zoneid', 'amt', 'payamt_coins') as $key) { $data['info'][$key] = $this->auth[$key]; } return Com_Queued::send('tencent_pay', json_encode($data)); // $this->record($data); }
/** * crontab 注册队列 */ public function register_trigger_mail() { return Com_Queued::register($this->_deal_mail_transfer_data, array($this, 'do_async_trigger_mail')); }
/** * crontab 注册队列 */ public function register_trigger_update_sweep_state() { return Com_Queued::register('async_update_sweep_state', array($this, 'do_async_trigger_update_sweep_state')); }
public function register_sys_like_friend_news() { return Com_Queued::register($this->_sys_like_friend_news, array($this, 'do_sys_set_data')); }
public function register() { return Com_Queued::register($this->_channel, array($this, 'receive')); }
public function register_online_stat() { return Com_Queued::register('async_online_stat', array($this, 'do_async_online_stat')); }
public function register_sys_add_union_log() { return Com_Queued::register($this->_sys_add_union_log, array($this, 'do_sys_add_union_log')); }
/** * crontab 注册队列 */ public function register_trigger_login_times() { return Com_Queued::register('async_update_login_times', array($this, 'do_async_trigger_login_times')); }
<?php /** * 异步腾讯 应用发货通知 * User: gufl@youzu.com * Date: 15-7-2 * Time: 下午10:52 */ require dirname(__FILE__) . '/../global.php'; TenYear::getInstance(); ini_set('default_socket_timeout', -1); Com_AdCache::factory()->set_timeout(0); $obj = new Game_Tencent(); $obj->register_push_to_tencent(); echo "register TencentPay receive \r\n"; echo "start receive \r\n"; //开始接收 Com_Queued::receive_all();
/** * crontab 注册队列 */ public function register_send_old_account_login_reward() { return Com_Queued::register('send_old_account_login_reward', array($this, 'do_async_send_old_account_login_reward')); }