public function __construct($dsn, $username = null, $password = null, $driver_options = array(), $config_key = null) { if (isset($driver_options[KalturaPDO::KALTURA_ATTR_NAME])) { $this->connectionName = $driver_options[KalturaPDO::KALTURA_ATTR_NAME]; $this->kalturaOptions = DbManager::getKalturaConfig($this->connectionName); } list($mysql, $connection) = explode(':', $dsn); $arguments = explode(';', $connection); foreach ($arguments as $argument) { list($argumentName, $argumentValue) = explode('=', $argument); if (strtolower($argumentName) == 'host') { $this->hostName = $argumentValue; break; } } $this->configKey = $config_key; $connStart = microtime(true); parent::__construct($dsn, $username, $password, $driver_options); $connTook = microtime(true) - $connStart; KalturaLog::debug("conn took - {$connTook} seconds to {$dsn}"); KalturaMonitorClient::monitorConnTook($dsn, $connTook); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('KalturaStatement')); }
/** * @return bool false on error */ protected function reconnect() { $this->memcache = null; if ($this->connectAttempts >= self::MAX_CONNECT_ATTEMPTS) { return false; } $connectResult = false; $connStart = microtime(true); while ($this->connectAttempts < self::MAX_CONNECT_ATTEMPTS) { $this->connectAttempts++; $memcache = new Memcache(); //$memcache->setOption(Memcached::OPT_BINARY_PROTOCOL, true); // TODO: enable when moving to memcached v1.3 $curConnStart = microtime(true); if ($this->persistent) { $connectResult = @$memcache->pconnect($this->hostName, $this->port); } else { $connectResult = @$memcache->connect($this->hostName, $this->port); } if ($connectResult || microtime(true) - $curConnStart < 0.5) { // retry only if there's an error and it's a timeout error break; } self::safeLog("got timeout error while connecting to memcache..."); } $connTook = microtime(true) - $connStart; self::safeLog("connect took - {$connTook} seconds to {$this->hostName}:{$this->port} attempts {$this->connectAttempts}"); if (class_exists("KalturaMonitorClient")) { KalturaMonitorClient::monitorConnTook($this->hostName, $connTook); } if (!$connectResult) { self::safeLog("failed to connect to memcache"); return false; } $this->memcache = $memcache; return true; }