本文整理汇总了PHP中Timer::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::read方法的具体用法?PHP Timer::read怎么用?PHP Timer::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
function query($sql, $verbose=false){
return new TestPostgrResult(array());
$sql = trim($sql);
if($this->_postgr_link === false){
$this->_postgr_link = pg_connect("host=" . $this->host . " user=" . $this->user . " password=" . $this->pass . " dbname=" . $this->database);
pg_query($this->_postgr_link, "SET NAMES 'utf8'");
}
if($this->_postgr_link === false){
throw new DatabaseException("could not connect to MySQL");
};
if($this->_query_cache->get($sql)){
if($verbose)echo "found in cache<br>";
$result = $this->_query_cache->get($sql);
if(pg_num_rows($result)){
if($verbose) echo ": seeking to 0";
pg_result_seek($result, 0);
}
$ret = new PostgrResult($this->_postgr_link, $result);
if($verbose) echo "<br>";
}else{
if($verbose) echo "not in cache";
$this->_query_count++;
/**
* this following line should be run once per connection to postgres
*
* i'm running it before every query. I can probably optimize this
* to run once per connection, but I need to do some thorough testing...
*
* http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html
*/
pg_query($this->_postgr_link, "SET NAMES 'utf8'");
$timer = new Timer();
$timer->start();
$result = pg_query($this->_postgr_link, $sql);
$ret = new PostgrResult($this->_postgr_link, $result);
$timer->stop();
$time = $timer->read();
if(is_object($this->logger)){
$this->logger->log($this, ALogger::$LOW, $sql);
}
/**
* the query is too long! oh noes!
*/
if($time > .1){
/**
* save the query to the DB, so I can look at it later
*/
if(is_object($this->logger)){
$this->logger->longQuery($time, $sql);
}
}
if(pg_last_error($this->_postgr_link)){
if($verbose) echo "postgr_error: " . pg_last_error($this->_postgr_link) . "<br>";
throw new DatabaseException(pg_last_error($this->_postgr_link));
}
if(strpos($sql, "SELECT") === 0){
if($verbose) echo ": select: $sql<br><br>";
$this->_query_cache->put($sql, $result);
}else{
if($verbose) echo ": not select: $sql<br>";
if($verbose) echo "clearing cache<br>";
$this->_query_cache->reset();
}
}
return $ret;
}
示例2: query
function query($sql, $verbose = false)
{
$sql = trim($sql);
if ($this->_mysqli_link === false) {
$this->_mysqli_link = mysqli_connect($this->host, $this->user, $this->pass, $this->database);
mysqli_set_charset($this->_mysqli_link, "utf8");
}
if ($this->_mysqli_link === false) {
throw new Exception("could not connect to MySQL");
}
if ($this->_query_cache->get($sql)) {
if ($verbose) {
echo "found in cache<br/>";
}
$result = $this->_query_cache->get($sql);
if (mysqli_num_rows($result)) {
if ($verbose) {
echo ": seeking to 0";
}
mysqli_data_seek($result, 0);
}
$ret = new MySQLResult($this->_mysqli_link, $result);
if ($verbose) {
echo "<br/>";
}
} else {
if ($verbose) {
echo "not in cache";
}
$this->_query_count++;
/**
* this following line should be run once per connection to mysql
*
* i'm running it before every query. I can probably optimize this
* to run once per connection, but I need to do some thorough testing...
*
* http://dev.mysql.com/doc/refman/5.6/en/charset-connection.html
*/
if (is_object($this->logger)) {
$this->logger->log($this, ALogger::$LOW, $sql);
}
mysqli_set_charset($this->_mysqli_link, "utf8");
$timer = new Timer();
$timer->start();
$result = mysqli_query($this->_mysqli_link, $sql);
$ret = new MySQLResult($this->_mysqli_link, $result);
$timer->stop();
$time = $timer->read();
/**
* the query is too long! oh noes!
*/
if ($time > 0.1) {
/**
* save the query to the DB, so I can look at it later
*/
if (is_object($this->logger)) {
$this->logger->longQuery($time, $sql);
}
}
if (mysqli_error($this->_mysqli_link)) {
if ($verbose) {
echo "mysqli_error: " . mysqli_error($this->_mysqli_link) . "<br>";
}
throw new Exception(mysqli_error($this->_mysqli_link));
}
if (strpos($sql, "SELECT") === 0) {
if ($verbose) {
echo ": select: {$sql}<br><br>";
}
$this->_query_cache->put($sql, $result);
} else {
if ($verbose) {
echo ": not select: {$sql}<br>";
}
if ($verbose) {
echo "clearing cache<br>";
}
$this->_query_cache->reset();
}
}
return $ret;
}