/** * Retrieve the namespace information for this connection. * * @return Horde_Kolab_Storage_Driver_Namespace The initialized namespace handler. */ public function getNamespace() { $this->_timer->push(); $result = parent::getNamespace(); $this->_logger->debug(sprintf('REQUEST OUT IMAP: %s ms [getNamespace]', floor($this->_timer->pop() * 1000))); return $result; }
/** * test getting the finish time before starting the timer */ public function testNotStartedYetThrowsException() { $t = new Horde_Support_Timer(); try { $t->pop(); $this->fail('Expected Exception'); } catch (Exception $e) { } }
/** * Convert the data to a XML stream. * * @param array $object The data array representing the object. * @param array $options Additional options when writing the XML. This * decorator provides no additional options. * * @return resource The data as XML stream. * * @throws Horde_Kolab_Format_Exception */ public function save($object, $options = array()) { $this->_timer->push(); $result = $this->getHandler()->save($object); $spent = $this->_timer->pop(); if (is_object($this->_logger)) { $this->_logger->debug(sprintf('Kolab Format data generation complete. Time spent: %s ms', floor($spent * 1000))); } self::$_spent += $spent; return $result; }
/** */ protected function _connect($host, $port, $timeout, $secure, $retries = 0) { if ($retries || !$this->_params['debug']->debug) { $timer = null; } else { $url = new Horde_Imap_Client_Url(); $url->hostspec = $host; $url->port = $port; $url->protocol = $this->_protocol; $this->_params['debug']->info(sprintf('Connection to: %s', strval($url))); $timer = new Horde_Support_Timer(); $timer->push(); } parent::_connect($host, $port, $timeout, $secure, $retries); if ($timer) { $this->_params['debug']->info(sprintf('Server connection took %s seconds.', round($timer->pop(), 4))); } }
/** */ protected function _connect($host, $port, $timeout, $secure, $context, $retries = 0) { if ($retries || !$this->_params['debug']->debug) { $timer = null; } else { $url = $this->_protocol == 'imap' ? new Horde_Imap_Client_Url_Imap() : new Horde_Imap_Client_Url_Pop3(); $url->host = $host; $url->port = $port; $this->_params['debug']->info(sprintf('Connection to: %s', strval($url))); $timer = new Horde_Support_Timer(); $timer->push(); } try { parent::_connect($host, $port, $timeout, $secure, $context, $retries); } catch (Horde\Socket\Client\Exception $e) { $this->_params['debug']->info(sprintf('Connection failed: %s', $e->getMessage())); throw $e; } if ($timer) { $this->_params['debug']->info(sprintf('Server connection took %s seconds.', round($timer->pop(), 4))); } }
/** * Perform a command on the server. A connection to the server must have * already been made. * * @param string $cmd The command to execute. * @param array $options Additional options: * <pre> * - debug: (string) When debugging, send this string instead of the * actual command/data sent. * DEFAULT: Raw data output to debug stream. * - multiline: (mixed) 'array', 'none', or 'stream'. * </pre> * * @return array See _getResponse(). * * @throws Horde_Imap_Client_Exception */ protected function _sendLine($cmd, $options = array()) { if (!empty($options['debug'])) { $this->_debug->client($options['debug']); } if ($this->_debug->debug) { $timer = new Horde_Support_Timer(); $timer->push(); } try { $this->_connection->write($cmd, empty($options['debug'])); } catch (Horde_Imap_Client_Exception $e) { throw $e; } $resp = $this->_getResponse(empty($options['multiline']) ? false : $options['multiline']); if ($this->_debug->debug) { $this->_debug->info(sprintf('Command took %s seconds.', round($timer->pop(), 4))); } return $resp; }
/** * Dispatch the request to the correct controller * * @param null|Mad_Controller_Request_Http $request * @param null|Mad_Controller_Response_Http $response * @return void */ public function dispatch($request = null, $response = null) { $t = new Horde_Support_Timer(); $t->push(); if ($response === null) { $response = new Mad_Controller_Response_Http(); } if ($request === null) { $request = new Mad_Controller_Request_Http(); } // request could not be parsed if ($request->isMalformed()) { $body = "Your request could not be understood by the server, " . "probably due to malformed syntax.\n\n"; $exc = $request->getException(); if ($exc && MAD_ENV != 'production') { $body .= $exc->getMessage(); } $response->setStatus(400); $response->setBody($body); // dispatch request to controller } else { $controller = $this->recognize($request); $response = $controller->process($request, $response); } $time = $t->pop(); $this->_logRequest($request, $time); $response->send(); }
/** * Execute this migration in the named direction */ public function migrate($direction) { if (!method_exists($this, $direction)) { return; } if ($direction == 'up') { $this->announce("migrating"); } if ($direction == 'down') { $this->announce("reverting"); } $result = null; $t = new Horde_Support_Timer(); $t->push(); $result = $this->{$direction}(); $time = $t->pop(); if ($direction == 'up') { $this->announce("migrated (" . sprintf("%.4fs", $time) . ")"); $this->log(); } if ($direction == 'down') { $this->announce("reverted (" . sprintf("%.4fs", $time) . ")"); $this->log(); } return $result; }
/** * Return the timer data. * * @return mixed Null if timer wasn't started, or a float containing * elapsed command time. */ public function getTimer() { return $this->_timer ? round($this->_timer->pop(), 4) : null; }
/** * Executes the SQL statement in the context of this connection. * * @deprecated Deprecated for external usage. Use select() instead. * * @param string $sql SQL statement. * @param mixed $arg1 Either an array of bound parameters or a query * name. * @param string $arg2 If $arg1 contains bound parameters, the query * name. * * @return PDOStatement * @throws Horde_Db_Exception */ public function execute($sql, $arg1 = null, $arg2 = null) { if (is_array($arg1)) { $sql = $this->_replaceParameters($sql, $arg1); $name = $arg2; } else { $name = $arg1; } $t = new Horde_Support_Timer(); $t->push(); try { $this->_lastQuery = $sql; $stmt = $this->_connection->query($sql); } catch (PDOException $e) { $this->_logInfo($sql, $name); $this->_logError($sql, 'QUERY FAILED: ' . $e->getMessage()); throw new Horde_Db_Exception($e); } $this->_logInfo($sql, $name, $t->pop()); $this->_rowCount = $stmt ? $stmt->rowCount() : 0; return $stmt; }
/** * Executes the SQL statement in the context of this connection. * * @param string $sql * @param mixed $arg1 Either an array of bound parameters or a query name. * @param string $arg2 If $arg1 contains bound parameters, the query name. */ public function execute($sql, $arg1 = null, $arg2 = null) { if (is_array($arg1)) { $sql = $this->_replaceParameters($sql, $arg1); $name = $arg2; } else { $name = $arg1; } $t = new Horde_Support_Timer(); $t->push(); $stmt = $this->_connection->query($sql); if (!$stmt) { $this->_logInfo($sql, 'QUERY FAILED: ' . $this->_connection->error); $this->_logInfo($sql, $name); throw new Horde_Db_Exception('QUERY FAILED: ' . $this->_connection->error . "\n\n" . $sql, $this->_errorCode($this->_connection->sqlstate, $this->_connection->errno)); } $this->_logInfo($sql, $name, $t->pop()); //@TODO if ($this->_connection->info) $this->_loginfo($sql, $this->_connection->info); //@TODO also log warnings? http://php.net/mysqli.warning-count and http://php.net/mysqli.get-warnings $this->_rowCount = $this->_connection->affected_rows; $this->_insertId = $this->_connection->insert_id; return $stmt; }
* @category Kolab * @package Kolab_Format * @author Gunnar Wrobel <*****@*****.**> * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * The Autoloader allows us to omit "require/include" statements. */ require_once 'Horde/Autoloader/Default.php'; /** Create the factory */ $factory = new Horde_Kolab_Format_Factory(); /** Generate the format handler */ $format = $factory->create('Xml', 'Event'); /** Prepare a test object */ if (!method_exists($format, 'getVersion')) { $object = array('uid' => 1, 'summary' => 'test event', 'start-date' => time(), 'end-date' => time() + 24 * 60 * 60); } else { $now = new DateTime(); $object = array('uid' => 1, 'summary' => 'test event', 'start-date' => array('date' => $now), 'end-date' => array('date' => $now)); } $timer = new Horde_Support_Timer(); $timer->push(); for ($i = 0; $i < 1000; $i++) { /** Save this test data array in Kolab XML format */ $xml = $format->save($object); /** Reload the object from the XML format */ $read_object = $format->load($xml); } var_dump($timer->pop());
/** * Executes the SQL statement in the context of this connection. * * @param string $sql SQL statement. * @param mixed $arg1 Either an array of bound parameters or a query * name. * @param string $arg2 If $arg1 contains bound parameters, the query * name. * * @return resource * @throws Horde_Db_Exception */ public function execute($sql, $arg1 = null, $arg2 = null, $lobs = array()) { if (is_array($arg1)) { $sql = $this->_replaceParameters($sql, $arg1); $name = $arg2; } else { $name = $arg1; } $t = new Horde_Support_Timer(); $t->push(); $this->_lastQuery = $sql; $stmt = @oci_parse($this->_connection, $sql); $descriptors = array(); foreach ($lobs as $name => $lob) { $descriptors[$name] = oci_new_descriptor($this->_connection, OCI_DTYPE_LOB); oci_bind_by_name($stmt, ':' . $name, $descriptors[$name], -1, $lob instanceof Horde_Db_Value_Binary ? OCI_B_BLOB : OCI_B_CLOB); } $flags = $lobs ? OCI_DEFAULT : ($this->_transactionStarted ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS); if (!$stmt || !@oci_execute($stmt, $flags)) { $error = oci_error($stmt ?: $this->_connection); if ($stmt) { oci_free_statement($stmt); } $this->_logInfo($sql, $name); $this->_logError($sql, 'QUERY FAILED: ' . $error['message']); throw new Horde_Db_Exception($this->_errorMessage($error), $error['code']); } foreach ($lobs as $name => $lob) { $descriptors[$name]->save($lob->value); } if ($lobs) { oci_commit($this->_connection); } $this->_logInfo($sql, $name, $t->pop()); $this->_rowCount = oci_num_rows($stmt); return $stmt; }
/** * Make sure we always disconnect after tests */ public function runBare() { // log test timing $test = get_class($this) . '::' . $this->getName(); $t = new Horde_Support_Timer(); $t->push(); $this->_logInfo($test, 'START '); $this->_connect(); parent::runBare(); $this->_disconnect(); // log test timing $elapsed = $t->pop(); $this->_logInfo($test, 'FINISH', $elapsed); }
/** * Executes the SQL statement in the context of this connection. * * @deprecated Deprecated for external usage. Use select() instead. * * @param string $sql SQL statement. * @param mixed $arg1 Either an array of bound parameters or a query * name. * @param string $arg2 If $arg1 contains bound parameters, the query * name. * * @return resource * @throws Horde_Db_Exception */ public function execute($sql, $arg1 = null, $arg2 = null) { if (is_array($arg1)) { $sql = $this->_replaceParameters($sql, $arg1); $name = $arg2; } else { $name = $arg1; } $t = new Horde_Support_Timer(); $t->push(); $this->_lastQuery = $sql; $stmt = mysql_query($sql, $this->_connection); if (!$stmt) { $this->_logInfo($sql, $name); $this->_logError($sql, 'QUERY FAILED: ' . mysql_error($this->_connection)); throw new Horde_Db_Exception('QUERY FAILED: ' . mysql_error($this->_connection) . "\n\n" . $sql, $this->_errorCode(null, mysql_errno($this->_connection))); } $this->_logInfo($sql, $name, $t->pop()); $this->_rowCount = mysql_affected_rows($this->_connection); $this->_insertId = mysql_insert_id($this->_connection); return $stmt; }