コード例 #1
0
ファイル: Dispatcher.php プロジェクト: lerre/framework
 /**
  * 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();
 }
コード例 #2
0
ファイル: TimerTest.php プロジェクト: x59/horde-support
 /**
  * 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) {
     }
 }
コード例 #3
0
ファイル: Cli.php プロジェクト: raz0rsdge/horde
 /**
  * The main entry point for the application.
  *
  * @param array $parameters A list of named configuration parameters.
  * <pre>
  * 'parser'   - (array)     Parser configuration parameters.
  *   'class'  - (string)    The class name of the parser to use.
  * 'output'   - (Horde_Cli) The output handler.
  * </pre>
  */
 public static function main(array $parameters = array())
 {
     $modular = self::_prepareModular($parameters);
     if (empty($parameters['output'])) {
         if (!class_exists('Horde_Cli')) {
             throw new Horde_Kolab_Cli_Exception('The Horde_Cli package seems to be missing (Class Horde_Cli is missing)!');
         }
         $cli = Horde_Cli::init();
     } else {
         $cli = $parameters['output'];
     }
     $parser = $modular->createParser();
     list($options, $arguments) = $parser->parseArgs();
     if (count($arguments) == 0) {
         $parser->printHelp();
     } else {
         try {
             if (!empty($options['config'])) {
                 if (!file_exists($options['config'])) {
                     throw new Horde_Kolab_Cli_Exception(sprintf('The specified config file %s does not exist!', $options['config']));
                 }
                 global $conf;
                 include $options['config'];
                 foreach ($conf as $key => $value) {
                     $options->ensureValue($key, $value);
                 }
             }
             if (empty($options['host'])) {
                 $options['host'] = 'localhost';
             }
             if (empty($options['driver'])) {
                 $options['driver'] = 'horde';
             }
             $world = array();
             foreach ($modular->getModules() as $module) {
                 $modular->getProvider()->getModule($module)->handleArguments($options, $arguments, $world);
             }
             if (!empty($options['timed']) && class_exists('Horde_Support_Timer')) {
                 $timer = new Horde_Support_Timer();
                 $timer->push();
             } else {
                 $timer = false;
             }
             $modular->getProvider()->getModule(Horde_String::ucfirst($arguments[0]))->run($cli, $options, $arguments, $world);
             if (!empty($options['timed'])) {
                 if ($timer) {
                     $cli->message(floor($timer->pop() * 1000) . ' ms');
                 } else {
                     $cli->message('The class Horde_Support_Timer seems to be missing!');
                 }
             }
         } catch (Horde_Cli_Modular_Exception $e) {
             $parser->printHelp();
         }
     }
 }
コード例 #4
0
ファイル: Timer.php プロジェクト: raz0rsdge/horde
 /**
  * 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;
 }
コード例 #5
0
ファイル: Base.php プロジェクト: pzhu2004/moodle
 /**
  */
 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)));
     }
 }
コード例 #6
0
ファイル: Timed.php プロジェクト: jubinpatel/horde
 /**
  * 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;
 }
コード例 #7
0
ファイル: Base.php プロジェクト: horde/horde
 /**
  */
 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)));
     }
 }
コード例 #8
0
ファイル: Base.php プロジェクト: horde/horde
 /**
  * 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;
 }
コード例 #9
0
ファイル: Command.php プロジェクト: pzhu2004/moodle
 /**
  * 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;
 }
コード例 #10
0
ファイル: Base.php プロジェクト: horde/horde
 /**
  * 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;
 }
コード例 #11
0
ファイル: Factory.php プロジェクト: horde/horde
 /**
  * Create the storage backend driver.
  *
  * @param array $params Any parameters that should overwrite the default
  *                      parameters provided in the factory constructor.
  *
  * @return Horde_Kolab_Storage_Driver The storage handler.
  */
 public function createDriver($params = array())
 {
     $params = array_merge($this->_params, $params);
     if (!isset($params['driver'])) {
         throw new Horde_Kolab_Storage_Exception(Horde_Kolab_Storage_Translation::t('Missing "driver" parameter!'));
     }
     if (isset($params['params'])) {
         $config = (array) $params['params'];
     } else {
         $config = array();
     }
     if (empty($config['host'])) {
         $config['host'] = 'localhost';
     }
     if (empty($config['port'])) {
         $config['port'] = 143;
     }
     if (isset($this->_params['log']) && (in_array('debug', $this->_params['log']) || in_array('driver_time', $this->_params['log']))) {
         $timer = new Horde_Support_Timer();
         $timer->push();
     }
     switch ($params['driver']) {
         case 'mock':
             if (!isset($config['data'])) {
                 $config['data'] = array('user/test' => array());
             }
             $driver = new Horde_Kolab_Storage_Driver_Mock($this, $config);
             break;
         case 'horde':
         case 'horde-php':
             $driver = new Horde_Kolab_Storage_Driver_Imap($this, $config);
             break;
         case 'php':
             $driver = new Horde_Kolab_Storage_Driver_Cclient($this, $config);
             break;
         case 'pear':
             $driver = new Horde_Kolab_Storage_Driver_Pear($this, $config);
             break;
         case 'roundcube':
             $driver = new Horde_Kolab_Storage_Driver_Rcube($this, $config);
             break;
         default:
             throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t('Invalid "driver" parameter "%s". Please use one of "mock", "php", "pear", "horde", "horde-php", and "roundcube"!'), $params['driver']));
     }
     if (isset($this->_params['log']) && (in_array('debug', $this->_params['log']) || in_array('driver', $this->_params['log']))) {
         $driver = new Horde_Kolab_Storage_Driver_Decorator_Log($driver, $params['logger']);
     }
     if (isset($this->_params['log']) && (in_array('debug', $this->_params['log']) || in_array('driver_time', $this->_params['log']))) {
         $driver = new Horde_Kolab_Storage_Driver_Decorator_Timer($driver, $timer, $params['logger']);
     }
     $this->_driver = $driver;
     return $driver;
 }
コード例 #12
0
ファイル: Unit.php プロジェクト: lerre/framework
 /**
  * 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);
 }
コード例 #13
0
ファイル: speed_check.php プロジェクト: jubinpatel/horde
 *
 * @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());
コード例 #14
0
ファイル: Oci8.php プロジェクト: raz0rsdge/horde
 /**
  * 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;
 }
コード例 #15
0
ファイル: Mysqli.php プロジェクト: lerre/framework
 /**
  * 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;
 }
コード例 #16
0
ファイル: Pop3.php プロジェクト: raz0rsdge/horde
 /**
  * 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;
 }
コード例 #17
0
ファイル: Mysql.php プロジェクト: horde/horde
 /**
  * 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;
 }