public function customErrorHander($errno, $errstr, $errfile, $errline) { $msg = sprintf("%s: \nIn file %s line %s\nMessage:%s", $this->getErrorLevel($errno), $errfile, $errline, $errstr); if ($this->logger) { $this->logger->writeError($msg); } }
protected function remoteImageExists($img) { try { $result = file_get_contents($img, false, null, 0, 1); } catch (Exception $ignored) { $this->LOG->error("remoteImageExists -> file_get_contents failed"); return false; } return $result !== false; }
protected function dataExchange() { $TcpSocketClientConnector = new TcpSocketClientConnector($this->_logger, 'tcp', $this->_synchronization->remote_server_ip, $this->_synchronization->tcp_client_command_port); // send to server $TcpSocketClientConnector->onSentMessage = function ($coming_message) { // $this->_logger->log(' $comming_message '.print_r($coming_message,1)); $answer = 'FALSE'; $exchangeArray = array(ExchangeODSS::getInstance()); foreach ($exchangeArray as &$exchangeItem) { if ($exchangeItem->init($coming_message)) { $answer = $exchangeItem->clientMessage(); } else { $exchangeItem->getErrors(); $this->_logger->log(' ERRORS ' . print_r($exchangeItem->getErrors(), 1)); } } return $answer; }; $TcpSocketClientConnector->onCloseConnection = function ($serverMessage) { $this->_logger->log(' $serverMessage ' . print_r(@unserialize($serverMessage), 1)); $exchangeArray = array(ExchangeODSS::getInstance()); foreach ($exchangeArray as &$exchangeItem) { if ($exchangeItem->init($serverMessage)) { if ($exchangeItem->closeConnection()) { return true; } } } return false; }; //comes messages $TcpSocketClientConnector->onReceiveDataMessage = function ($message) { //$this->_logger->log(__METHOD__.' $message : '. print_r($message,1)); $validMessage = "FALSE"; $exchangeArray = array(ExchangeODSS::getInstance()); foreach ($exchangeArray as &$exchangeItem) { if ($exchangeItem->init($message)) { $validMessage = $exchangeItem->returnReceivedMessage(); } else { $exchangeItem->getErrors(); $this->_logger->log(' ERRORS ' . print_r($exchangeItem->getErrors(), 1)); } } return $validMessage; }; $exchangeArray = array(ExchangeODSS::getInstance()); foreach ($exchangeArray as &$exchangeItem) { $TcpSocketClientConnector->connect($timeout = 1); $messageToServer = $exchangeItem->clientMessage(); $this->_logger->log(' $messageToServer ' . print_r($messageToServer, 1)); $TcpSocketClientConnector->sendMessage($messageToServer, $timeout = 1); } }
/** * Function returns array of periods. Script is able to generate schedule for these periods only. * * @param int $generationTime * @return array */ public static function getProperPeriods($generationTime) { self::$_logger->log(__METHOD__, array('generationTime' => $generationTime)); $compare_min = null; $cur_hour = date('H', $generationTime); $cur_min = date('i', $generationTime); if ($cur_min >= 0 && $cur_min <= 14) { $compare_min = '00'; } elseif ($cur_min >= 15 && $cur_min <= 29) { $compare_min = '15'; } elseif ($cur_min >= 30 && $cur_min <= 44) { $compare_min = '30'; } if ($cur_min >= 45 && $cur_min <= 59) { $compare_min = '45'; } $cur_time = $cur_hour . ':' . $compare_min; $proper_periods = array(); $scheduler = ['1' => self::generatePeriodArray(1), '5' => self::generatePeriodArray(5), '15' => ['00:00', '00:15', '00:30', '00:45', '01:00', '01:15', '01:30', '01:45', '02:00', '02:15', '02:30', '02:45', '03:00', '03:15', '03:30', '03:45', '04:00', '04:15', '04:30', '04:45', '05:00', '05:15', '05:30', '05:45', '06:00', '06:15', '06:30', '06:45', '07:00', '07:15', '07:30', '07:45', '08:00', '08:15', '08:30', '08:45', '09:00', '09:15', '09:30', '09:45', '10:00', '10:15', '10:30', '10:45', '11:00', '11:15', '11:30', '11:45', '12:00', '12:15', '12:30', '12:45', '13:00', '13:15', '13:30', '13:45', '14:00', '14:15', '14:30', '14:45', '15:00', '15:15', '15:30', '15:45', '16:00', '16:15', '16:30', '16:45', '17:00', '17:15', '17:30', '17:45', '18:00', '18:15', '18:30', '18:45', '19:00', '19:15', '19:30', '19:45', '20:00', '20:15', '20:30', '20:45', '21:00', '21:15', '21:30', '21:45', '22:00', '22:15', '22:30', '22:45', '23:00', '23:15', '23:30', '23:45'], '30' => ['00:00', '00:30', '01:00', '01:30', '02:00', '02:30', '03:00', '03:30', '04:00', '04:30', '05:00', '05:30', '06:00', '06:30', '07:00', '07:30', '08:00', '08:30', '09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00', '19:30', '20:00', '20:30', '21:00', '21:30', '22:00', '22:30', '23:00', '23:30'], '60' => ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'], '120' => ['00:00', '02:00', '04:00', '06:00', '08:00', '10:00', '12:00', '16:00', '18:00', '20:00', '22:00'], '180' => ['00:00', '03:00', '06:00', '09:00', '12:00', '15:00', '18:00', '21:00'], '360' => ['00:00', '06:00', '12:00', '18:00'], '540' => ['00:00', '09:00', '18:00', '03:00', '12:00', '21:00', '06:00', '15:00'], '720' => ['00:00', '12:00'], '900' => ['00:00', '15:00', '06:00', '21:00', '12:00', '03:00', '18:00', '09:00'], '1080' => ['00:00', '18:00', '12:00', '06:00'], '1440' => ['00:00']]; foreach ($scheduler as $key => $value) { if (in_array($cur_time, $value)) { $proper_periods[] = $key; } } self::$_logger->log(__METHOD__, array('proper_periods' => implode(',', $proper_periods))); return $proper_periods; }
private function getNextIdFromDb() { try { $next_id = $this->dbhelper->executeInsert("INSERT INTO " . $this->key_prefix . $this->table_name . " VALUES (null)"); } catch (DBException $e) { $next_id = 0; $this->logger->writeError("db exception happens while generate sequence id." . $e->getMessage()); } return $next_id; }
public function flush() { $this->connect(); $res = $this->cache->flush(); if ($res === false) { $this->logger->writeError("failed to flush memcache server[" . implode(',', $this->host) . "]."); } if ($this->logger->isDebugEnabled()) { $this->logger->writeDebug("[flush]"); } return $res; }
protected function sendReport($sendLogObject) { if (is_object($sendLogObject->report_processed->ex_schedule_report)) { $file_name = $sendLogObject->report_processed->getFileName($sendLogObject->report_processed->ex_schedule_report); $file_path = $sendLogObject->report_processed->full_file_name; if ($sendLogObject->destination->method === 'mail') { $this->logger->log(__METHOD__, array('method' => $sendLogObject->destination->method, 'email' => $sendLogObject->destination->destination_email)); $mail_params = array('actuality_time' => $sendLogObject->created, 'schedule_period' => '', 'report_file_name' => $file_name, 'link' => '', 'report_type' => $sendLogObject->report_processed->ex_schedule_report->report_type); $subject = Yii::t('letter', 'scheduled_report_mail_subject', $mail_params, null, 'en'); $settings = Settings::model()->findByPk(1); $mailSender = new mailSender('odss_reports', array()); $sendResult = $mailSender->setAttachments(array(array('file_path' => $file_path, 'file_name' => $file_name)))->setRecipient($sendLogObject->destination->destination_email)->setFrom($settings->mail__sender_address, $settings->mail__sender_name)->setSubject($subject)->setHtmlBody()->send(); if ($sendResult !== false) { $sendLogObject->sent = 1; $sendLogObject->save(); } $this->logger->log(__METHOD__ . ' $sendResult: ' . $sendResult); $this->logger->log(__METHOD__ . ' Message send with attached file'); $this->logger->log(__METHOD__ . ' Deliver via mail DONE.'); } else { if ($sendLogObject->destination->method === 'ftp') { // use it if you have some superstition about "../" // $fileCopier = new FileCopier; // $file_path = $fileCopier->rmPathSteps($file_path); $ftpClient = new FtpClient(); $errors = $ftpClient->connect($sendLogObject->destination->destination_ip, $sendLogObject->destination->destination_ip_port)->login($sendLogObject->destination->destination_ip_user, $sendLogObject->destination->destination_ip_password)->setFolder($sendLogObject->destination->destination_ip_folder)->openLocalFile($file_path)->upload($file_name)->closeLocalFile()->getErrors(); if (!count($errors)) { $sendLogObject->sent = 1; $sendLogObject->save(); } else { $sendLogObject->send_logs = serialize($errors); $sendLogObject->save(); } $this->logger->log(__METHOD__ . " ftp errors:" . print_r($errors, 1)); $this->logger->log(__METHOD__ . ' Deliver via ftp DONE.'); } else { if ($sendLogObject->destination->method === 'local_folder') { $this->logger->log(__METHOD__, array('report_type' => $sendLogObject->report_processed->ex_schedule_report->report_type, 'method' => $sendLogObject->destination->method, 'destination_folder' => $sendLogObject->destination->destination_local_folder)); $destinationPath = $sendLogObject->report_processed->getFileDir() . DIRECTORY_SEPARATOR . $sendLogObject->destination->destination_local_folder; $this->logger->log(__METHOD__ . ' $file_path: ' . $file_path); $this->logger->log(__METHOD__ . ' $destinationPath: ' . $destinationPath); $this->logger->log(__METHOD__ . ' $file_name: ' . $file_name); $fileCopier = new FileCopier(); $errors = $fileCopier->copy($file_path, $destinationPath . DIRECTORY_SEPARATOR . $file_name)->getErrors(); if (!count($errors)) { $sendLogObject->sent = 1; $sendLogObject->save(); } else { $sendLogObject->send_logs = serialize($errors); $sendLogObject->save(); } $this->logger->log(__METHOD__ . ' errors:' . print_r($errors, 1)); $this->logger->log(__METHOD__ . ' Deliver to local folder DONE.'); } } } } }
protected function pollData($address, $port, $command) { $this->_logger->log(__METHOD__, array('address' => $address, 'port' => $port, 'command' => $command)); $timeout = 6; // !!! PROTOCOL (TCP by default) SHOULD BE IN LOWER CASE !!! $uri = 'tcp' . '://' . $address . ':' . $port; $this->_logger->log(__METHOD__ . ': Trying to connect', array('uri' => $uri, 'timeout' => $timeout)); // creates socket connection with IP:port $client = @stream_socket_client($uri, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT); if ($client === false) { $this->_logger->log(__METHOD__ . ': Client connect error', array('error' => $errstr, 'number' => $errno)); return false; } @stream_set_timeout($client, $timeout); $this->_logger->log(__METHOD__ . ': Sending command', array('command' => $command)); $status = @stream_socket_sendto($client, $command . "\n"); if ($status === false) { $erroInfo = $this->getSocketErrorInfo($client); $this->_logger->log(__METHOD__ . ': Error on sending command', array('error' => $erroInfo['error'], 'number' => $erroInfo['number'])); @stream_socket_shutdown($client, STREAM_SHUT_RDWR); return false; } $this->_logger->log(__METHOD__ . ': Sent result', array('Bytes sent' => $status)); //$time = 0; $line = null; $message = ''; $attempt = 1; $this->_logger->log(__METHOD__ . ': Starting to read response.'); // Wait for message end while (strpos($line, '$') === false) { $line = @fread($client, 1024); $this->_logger->log(__METHOD__, array('read line' => $line)); if (strlen($line) === 0) { $this->_logger->log(__METHOD__ . ': Reading timeout exceeded.', array('attempt' => $attempt)); if ($attempt > 2) { $this->_logger->log(__METHOD__ . ': Exceeded maximun attempt number.'); @stream_socket_shutdown($client, STREAM_SHUT_RDWR); return false; } } $message .= $line; $attempt++; } @stream_socket_shutdown($client, STREAM_SHUT_RDWR); $this->_logger->log(__METHOD__, array('return' => $message)); return $message; }
public function dataExchange() { $TcpSocketServerConnector = new TcpSocketServerConnector($this->_logger, 'tcp', $this->_synchronization->server_ip, $this->_synchronization->tcp_server_command_port); $TcpSocketServerConnector->loadData($null); // send answer to client $TcpSocketServerConnector->onSentMessage = function ($coming_message) { $this->_logger->log(' $comming_message ' . print_r($coming_message, 1)); $answer = 'FALSE'; $exchangeArray = array(ExchangeODSS::getInstance()); foreach ($exchangeArray as &$exchangeItem) { // if ($exchangeItem->init($coming_message)) { $answer = $exchangeItem->serverMessage(); } else { $exchangeItem->getErrors(); $this->_logger->log(' ERRORS ' . print_r($exchangeItem->getErrors(), 1)); } } $this->_logger->log(' $answer ' . print_r($answer, 1)); return $answer; }; $TcpSocketServerConnector->onCloseConnection = function ($clientMessage) { $this->_logger->log(' $clientMessage ' . print_r(@unserialize($clientMessage), 1)); $exchangeArray = array(ExchangeODSS::getInstance()); foreach ($exchangeArray as &$exchangeItem) { // if ($exchangeItem->init($clientMessage)) { if ($exchangeItem->closeConnection()) { return true; } } } return false; }; //comes messages $TcpSocketServerConnector->onReceiveDataMessage = function ($message) { $this->_logger->log(' $message : ' . print_r($message, 1)); $validMessage = "FALSE"; $exchangeArray = array(ExchangeODSS::getInstance()); foreach ($exchangeArray as &$exchangeItem) { if ($exchangeItem->init($message)) { $validMessage = $exchangeItem->returnReceivedMessage(); } else { $exchangeItem->getErrors(); $this->_logger->log(' onReceiveDataMessage ERRORS ' . print_r($exchangeItem->getErrors(), 1)); } } return $validMessage; }; $TcpSocketServerConnector->readData($message); }
protected function getSQL($sql, $params = null) { $format_sql = $sql; if (is_array($params)) { $format_sql = vsprintf($sql, $params); } elseif (!is_null($params)) { $format_sql = sprintf($sql, $params); } if ($format_sql === false) { $this->logger->writeError("the composit sql is false, check it:[sql={$sql}, param={$params}]"); } if ($this->logger->isDebugEnabled()) { $this->logger->writeDebug("trying to exectue sql[db_helper=%s,host=%s,db=%s] : %s", array(spl_object_hash($this), $this->config['host'], $this->config['database'], $format_sql)); } return $format_sql; }
protected function showWarning($expire, $maxMinutes, $usage) { $title = 'System Usage Time Limit'; $minutesDurationRemain = $maxMinutes - $usage; $msg = "Duration remaining: {$minutesDurationRemain} minutes. Time expires in {$expire} minutes."; $this->log->info($msg); $this->system->writeStatus($msg); $remain = min($minutesDurationRemain, $expire); if ($remain <= 30 && $remain > 0 && $remain % 5 == 0 || $remain == 1) { $this->system->showAlert($title, "{$remain} minutes remaining."); } }
/** * Receive the Logger update and writes the log event using the formatter */ public function update(ILogger $logger) { if ($this->level <= $logger->getMessageLevel()) { $this->write($logger->getFormatter()->format($logger->getEvent())); } }
/** * @param $params */ public function execute($params = null) { try { if ($this->isServiceClosed($params['gameuid'])) { return $this->getReturnArray(GameStatusCode::SYSTEM_MAINTAIN, 'service closed.'); } // return $this->getReturnArray(0,'ok',"test"); if (isset($params['gameuid'])) { $gameuid = intval($params['gameuid']); if ($gameuid <= 0) { $this->throwException("user[{$gameuid}] not exists", GameStatusCode::USER_NOT_EXISTS); } if (isset($params['friend_gameuid'])) { if (empty($params['friend_gameuid']) || $params['friend_gameuid'] <= 0) { $this->throwException("friend user[" . $params['friend_gameuid'] . "] not exist", GameStatusCode::USER_NOT_EXISTS); } } $this->action_logger = new UserActionLogManager($gameuid); $this->user_account = $this->user_account_mgr->getUserAccount($gameuid); if (empty($this->user_account)) { $this->throwException("user[{$gameuid}] not exists", GameStatusCode::USER_NOT_EXISTS); } // //是否被禁用 // if($this->user_account['disabled'] == "1"){ // return $this->getReturnArray(GameStatusCode::USER_NOT_EXISTS,"user[$gameuid] is disbaled."); // } // $this->checkSession($gameuid); } // 对参数做处理 $this->params = $params; // if(!$this->isPerfTestMode($params['gameuid'])){ // if(!get_app_config()->getGlobalConfig("debug_mode")){ // $this->checkSignature($params); // } // $this->validate(); // } $now = time(); //调用游戏接口 $result = $this->_exec(); // // 根据动作的定义,获取用户的经验值和金币的修改值 // $modify = array_intersect_key($result,array('coin'=>0,'money'=>0,'coupon'=>0,'experience'=>0)); // if (isset($this->params['action_id'])) { // if (intval($this->action_def['coin']) != 0) $modify['coin'] += intval($this->action_def['coin']); // if (intval($this->action_def['experience']) != 0) $modify['experience'] += intval($this->action_def['experience']); // } // // //修改用户的经验值和金币数量 // if (count($modify) > 0) { // $this->user_account_mgr->updateUserStatus($gameuid, $modify); // $result = array_merge($result, $modify); // } // // //检查action是否要进行计数 // if (isset($this->params['action_id'])&&in_array($this->params['action_id'], $this->action_record_count)){ // UserActionCountManager::updateActionCount($this->params['gameuid'],$this->params['action_id']); // } // //判断是否要写actionlog日志 // if (!empty($modify) && isset($this->params['action_id'])){ // $action_log_params=array(); // $action_log_params=$modify; // if (isset($result['action_log_params'])){ // $action_log_params['content']=$result['action_log_params']['content']; // unset($result['action_log_params']); // } // $this->action_logger->writeLog($this->params['action_id'], $action_log_params); // } //如果有eventlog,则写log日志,同时将返回值中的相关信息删除 if (isset($result['event_log_params']) && is_array($result['event_log_params'])) { $event_log_params = $result['event_log_params']; $event_gameuid = $event_log_params['gameuid']; $event_action_id = $event_log_params['action_id']; $event_params = $event_log_params['params']; $event_logger = new UserEventLogManager($event_gameuid); $event_logger->writeLog($event_action_id, $event_params); unset($result['event_log_params']); } return $this->getReturnArray(0, 'ok', $result); } catch (DBException $e) { // 数据库类型的错误特殊处理 $this->logger->writeError("database exception happens while execute sql, error_msg:" . $e->getMessage()); $this->logger->writeError("and the stack trace is as below:\n" . $e->getTraceAsString()); if (get_app_config()->getGlobalConfig("debug_mode")) { return $this->getReturnArray(GameStatusCode::DATABASE_ERROR, $e->getMessage()); } else { return $this->getReturnArray(GameStatusCode::DATABASE_ERROR, 'database error'); } } catch (GameException $e) { $this->logger->writeError("game exception happens while execute action:" . $e); //log输出过多,关闭之 return $this->getReturnArray($e->getCode(), $e->getMessage()); } catch (Exception $e) { // 其他的错误 $this->logger->writeError("unknown exception happens while execute action." . $e->getTraceAsString()); return $this->getReturnArray(GameStatusCode::UNKNOWN_ERROR, $e->getMessage()); } return $this->getReturnArray(GameStatusCode::UNKNOWN_ERROR, ''); }
protected function deleteFromCache() { switch ($this->cache_type) { case self::CACHE_KEY_LIST: $cache = $this->getCacheInstance(); $cache_list_key = $this->getListCacheKey(); $cached_list = $cache->get($cache_list_key); foreach ($cached_list as $cached_entry) { $cache->delete($this->getTableMemkey($cached_entry)); } $cache->delete($cache_list_key); break; case self::CACHE_IN_LIST: case self::CACHE_PRIMARY_KEY: $cache = $this->getCacheInstance(); $deleted_vals = array(); if ($this->affected_rows <= 1) { $primary_key = $this->getPrimaryKey(); $deleted_vals[] = array_intersect_key($this->keys, $primary_key); } else { $primary_key = $this->getPrimaryKey(); foreach ($this->keys as $field => $val) { $fields = explode(",", $field); if (count($fields) > 1) { if ($fields != array_keys($primary_key)) { continue; } foreach ($val as $v) { $arr = array_combine($fields, $v); if ($arr === false) { continue; } $deleted_vals[] = $arr; } } else { if (array($field) != array_keys($primary_key)) { continue; } if (is_array($val)) { foreach ($val as $v) { $deleted_vals[] = array($field => $v); } } else { $deleted_vals[] = array($field => $v); } } } } foreach ($deleted_vals as $deleted_val) { $cache->delete($this->getTableMemkey($deleted_val)); } // 将相应的cache_list里边的元素删除掉 $cached_list_key = $this->getListCacheKey(); $cached_list = $cache->get($cached_list_key); foreach ($deleted_vals as $deleted_val) { foreach ($cached_list as $k => $v) { if ($v == $deleted_val) { unset($cached_list[$k]); } } } if (empty($cached_list)) { if ($this->logger->isDebugEnabled()) { $this->logger->writeDebug("[deleteFromCache]tring to delete list cache[key={$cache_list_key}]"); } $cache->delete($cached_list_key); } else { if ($this->logger->isDebugEnabled()) { $this->logger->writeDebug("tring to delete item in list cache[key={$cached_list_key},value=" . print_r($cached_list, true) . "]"); } $cache->set($cached_list_key, $cached_list, 0); } break; } }
/** * * @param string $method * @param type $result * @return type */ protected function returnResult($method, $result) { $this->_logger->log($method, array('Return value' => $result)); return $result; }