Exemple #1
0
 private function _errorHandler()
 {
     restore_error_handler();
     $error = func_get_args();
     if (!($error[0] & error_reporting())) {
         KC_LOG_DEBUG('caught info, errno:%d,errmsg:%s,file:%s,line:%d', $error[0], $error[1], $error[2], $error[3]);
         set_error_handler(array($this, 'errorHandler'));
         return false;
     } elseif ($error[0] === E_USER_NOTICE) {
         KC_LOG_TRACE('caught trace, errno:%d,errmsg:%s,file:%s,line:%d', $error[0], $error[1], $error[2], $error[3]);
         set_error_handler(array($this, 'errorHandler'));
         return false;
     } elseif ($error[0] === E_STRICT) {
         set_error_handler(array($this, 'errorHandler'));
         return false;
     } else {
         KC_LOG_FATAL('caught error, errno:%d,errmsg:%s,file:%s,line:%d', $error[0], $error[1], $error[2], $error[3]);
         $this->endStatus = 'error';
         return true;
     }
 }
 /**
  * 
  * 执行一条SQL语句
  * @param string $sql 要执行的SQL语句
  */
 public function query($sql)
 {
     $start = intval(microtime(true) * 1000);
     if (!$this->_isConnected) {
         KC_LOG_WARNING(__FUNCTION__ . " failed, db has not been connected [ sql: {$sql} ]");
         return false;
     }
     $result = $this->_mysqli->query($sql);
     $end = intval(microtime(true) * 1000);
     $cost = $end - $start;
     if (false === $result && $this->_mysqli->errno) {
         KC_LOG_WARNING("execute sql failed [ sql: {$sql}, error_info: " . $this->_mysqli->error . ', error_no: ' . $this->_mysqli->errno . ' ].');
         return false;
     }
     if (true === $result) {
         KC_LOG_TRACE("execute sql succ [ sql: {$sql}, ret: 'true', cost: {$cost} ms ].");
         return $result;
     }
     $ret = array();
     while ($row = $result->fetch_assoc()) {
         array_push($ret, $row);
     }
     $result->close();
     KC_LOG_TRACE("execute sql succ [ sql: {$sql}, count: " . count($ret) . ", cost: {$cost} ms ].");
     return $ret;
 }
Exemple #3
0
 /**
  * 批量设置key的信息
  * 
  * @param array $arrValues 要设置的key value对集合
  * @throws Exception
  */
 public function msetEx($arrValues)
 {
     if (!is_array($arrValues)) {
         throw new Exception('internal invalid $arrValues was received, no array [ keys: %s ].', $arrValues);
     }
     if (empty($arrValues)) {
         return;
     }
     $retry = 0;
     $ret = false;
     do {
         $this->getConnection($retry !== 0);
         try {
             $ret = $this->_redisObj->mset($arrValues);
         } catch (Exception $ex) {
             KC_LOG_WARNING('try to set multi-values to redis returned false [ retry: %s ].', $retry);
             sleep(1);
             $ret = false;
             continue;
         }
         break;
     } while ($retry++ < AppConf::$redisRetry);
     if (false === $ret) {
         throw new Exception('query redis to save all failed.');
     }
     KC_LOG_TRACE('function %s sycc [ count: %s ].', __FUNCTION__, count($arrValues));
 }