Exemplo n.º 1
0
 /**
  * This function measures the execution time of the given callback. It will be measured in seconds, with a precision
  * of 4 digits.
  * @param callback The callback to be called.
  * @param mixed Reference to the returnvalue container.
  * @param array An array which holds all the parameters for the callback
  * @return string The amount of time required for execution of the callback
  */
 public static final function timeCall($callback, &$returnVal, array $parameters = array())
 {
     if (is_callable($callback)) {
         $timer = new \System\Calendar\Timer();
         $timer->start();
         $returnVal = call_user_func_array($callback, $parameters);
         $timer->stop();
         return $timer->getDuration();
     } else {
         throw new \InvalidArgumentException('callback parameter is not a valid callback');
     }
 }
Exemplo n.º 2
0
 /**
  * Creates a new database resultset. This function is automatically called by the database and should not
  * be called directly.
  * @param \MySQLi The link to the database system
  * @param \System\Db\Query The query
  * @param \System\Db\Database The database issueing the request
  */
 public function __construct(\MySQLi $databaseLink, \System\Db\Query $query, \System\Db\Database $database)
 {
     $this->databaseLink = $databaseLink;
     $this->requestIssuer = $database;
     $this->query = $query;
     //increase its own querycounter
     self::$queryCount++;
     $timer = new \System\Calendar\Timer();
     $timer->start();
     $actualQuery = $query->getQuery();
     if (!($this->results = $databaseLink->query($actualQuery))) {
         throw new \System\Error\Exception\DatabaseQueryException('Query: ' . $actualQuery . ' - ' . $databaseLink->error);
     }
     /**
      * If there is a query that wants to execute the amount of found rows, we store this amount in the own vector.
      * Do note that this query gets logged before the actual query, because of the stackframe buildup. The actual execution order is correct
      */
     if (strpos($actualQuery, 'SQL_CALC_FOUND_ROWS') !== false) {
         $query = new \System\Db\Query($database, 'SELECT FOUND_ROWS() AS amount');
         $this->totalAmount = $database->queryScalar($query)->first();
     } else {
         $this->totalAmount = $this->count();
     }
     $timer->stop();
     $this->duration = $timer->getDuration();
     self::$totalQueryTime += $this->duration;
     if (round($timer->getDuration()) >= self::SLOW_QUERY_TIME) {
         $event = new \System\Event\Event\OnSlowMySQLQueryEvent();
         $event->setQuery($query);
         $event->setDuration($this->duration);
         $event->raise($this);
     }
     $this->rewind();
 }