/** * Generic request execution method * @param string $request The request string * @return resource The request results or an exception if any error occures */ protected function &request($request) { $timer = TimerTool::getInstance(); $timer->tick('Executing request (' . $this->dbName . ') : ' . $request, 'ms', 0, FALSE); $timer->incrementCount(); // Request execution $result = mysql_unbuffered_query($request, $this->dbLink); if (!$result) { $mysqlErrNo = mysql_errno($this->dbLink); $mysqlErrMsg = mysql_error($this->dbLink); // Mysql connection lost : reconnect and retry query if (!$this->isConnected()) { $logInstance = LogTool::getInstance(); $logInstance->logWarning('Connection lost (Error #' . $mysqlErrNo . ' : ' . $mysqlErrMsg . ') during request execution, will reconnect and retry it : ' . $request); $this->connect(); $logInstance->logWarning('Retrying request (' . $this->dbName . ') : ' . $request); $result = mysql_unbuffered_query($request, $this->dbLink); if (!$result) { throw DatabaseException::getSpecificException('Error while executing query (retry): "' . $request . '" (Error #' . $mysqlErrNo . ' : ' . $mysqlErrMsg . ')', $mysqlErrNo); } } else { throw DatabaseException::getSpecificException('Error while executing following query : "' . $request . '" (Error #' . $mysqlErrNo . ' : ' . $mysqlErrMsg . ')', $mysqlErrNo); } } $timer->tick('Finished executing request', 'ms', 0, TRUE); return $result; }
public function tick($logDebugText = '', $unit = 'ms', $roundPrecision = 0, $isMySQLTime = FALSE, $color = LogTool::COLOR_BLUE) { $logInstance = LogTool::getInstance(); if ($unit == 's') { $getTimeFunction = 'getTimeSeconds'; } else { $getTimeFunction = 'getTimeMicroseconds'; } // Write debug message $logInstance->logDebug((isset($this->countValue) ? '[Increment = ' . $this->countValue . ']' : '') . 'Timer: ' . round($this->{$getTimeFunction}(), $roundPrecision) . ' ' . $unit . ($this->lastTickTime ? ' (' . round($this->{$getTimeFunction}(TRUE), $roundPrecision) . ' ' . $unit . ' since last tick)' : '') . ' : ' . $logDebugText, $color); // Adds to cumulative timers if ($isMySQLTime) { $this->mysqlCumulativeTime += $this->getTimeMicroseconds(TRUE); LogTool::getInstance()->logTrace($color); } else { $this->phpCumulativeTime += $this->getTimeMicroseconds(TRUE); } // Remember current microTime $this->lastTickTime = TimerTool::getMicrotimeFloat(); }