当前位置: 首页>>代码示例>>PHP>>正文


PHP Timer::read方法代码示例

本文整理汇总了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;
	}
开发者ID:sdytrych,项目名称:drivesafetogether,代码行数:72,代码来源:class.PostgrConn.php

示例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;
 }
开发者ID:mhscientist,项目名称:json-to-mysql,代码行数:82,代码来源:class.MySQLConn.php


注:本文中的Timer::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。