mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°1260 MySQL connection : allow to use p: host prefix (persistent connection, see http://php.net/manual/en/mysqli.persistconns.php)
SVN:trunk[5316]
This commit is contained in:
@@ -174,11 +174,8 @@ class CMDBSource
|
||||
self::$m_sDBTlsCaPath = empty($sTlsCaPath) ? null : $sTlsCaPath;
|
||||
self::$m_sDBTlsCipher = empty($sTlsCipher) ? null : $sTlsCipher;
|
||||
|
||||
// when using TLS add persistent connection to reduce overhead
|
||||
$bUsePersistentConnection = self::IsDbConnectionUsingTls($sServer, $sServer, $sServer);
|
||||
|
||||
self::$m_oMysqli = self::GetMysqliInstance($sServer, $sUser, $sPwd, $sSource, $sTlsKey, $sTlsCert, $sTlsCA,
|
||||
$sTlsCaPath, $sTlsCipher, $bUsePersistentConnection, true);
|
||||
$sTlsCaPath, $sTlsCipher, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +188,6 @@ class CMDBSource
|
||||
* @param string $sTlsCa
|
||||
* @param string $sTlsCaPath
|
||||
* @param string $sTlsCipher
|
||||
* @param boolean $bUsePersistentConnection {@see http://php.net/manual/en/mysqli.persistconns.php}
|
||||
* @param boolean $bCheckTlsAfterConnection
|
||||
*
|
||||
* @return \mysqli
|
||||
@@ -199,7 +195,7 @@ class CMDBSource
|
||||
*/
|
||||
public static function GetMysqliInstance(
|
||||
$sServer, $sUser, $sPwd, $sSource = '', $sTlsKey = null, $sTlsCert = null, $sTlsCa = null, $sTlsCaPath = null,
|
||||
$sTlsCipher = null, $bUsePersistentConnection = false, $bCheckTlsAfterConnection = false
|
||||
$sTlsCipher = null, $bCheckTlsAfterConnection = false
|
||||
) {
|
||||
$oMysqli = null;
|
||||
|
||||
@@ -207,10 +203,6 @@ class CMDBSource
|
||||
$iPort = null;
|
||||
$bTlsEnabled = self::IsDbConnectionUsingTls($sTlsKey, $sTlsCert, $sTlsCa);
|
||||
self::InitServerAndPort($sServer, $iPort);
|
||||
if ($bUsePersistentConnection)
|
||||
{
|
||||
$sServer = 'p:'.$sServer;
|
||||
}
|
||||
|
||||
$iFlags = null;
|
||||
|
||||
@@ -263,7 +255,7 @@ class CMDBSource
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize variables from the static attribute (containing "domain:port" syntax)
|
||||
* Initialize variables from the static attribute (containing "p:domain:port" syntax)
|
||||
*
|
||||
* @param string $sServer
|
||||
* @param int $iPort
|
||||
@@ -271,16 +263,31 @@ class CMDBSource
|
||||
private static function InitServerAndPort(&$sServer, &$iPort)
|
||||
{
|
||||
$aConnectInfo = explode(':', self::$m_sDBHost);
|
||||
if (count($aConnectInfo) > 1)
|
||||
|
||||
$bUsePersistentConnection = false;
|
||||
if (strcasecmp($aConnectInfo[0], 'p') == 0)
|
||||
{
|
||||
// Override the default port
|
||||
$sServer = $aConnectInfo[0];
|
||||
$iPort = (int)$aConnectInfo[1];
|
||||
// we might have "p:" prefix to use persistent connections (see http://php.net/manual/en/mysqli.persistconns.php)
|
||||
$bUsePersistentConnection = true;
|
||||
$sServer = $aConnectInfo[0].':'.$aConnectInfo[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sServer = self::$m_sDBHost;
|
||||
$iPort = null;
|
||||
$sServer = $aConnectInfo[0];
|
||||
}
|
||||
|
||||
$iConnectInfoCount = count($aConnectInfo);
|
||||
if ($bUsePersistentConnection && ($iConnectInfoCount == 3))
|
||||
{
|
||||
$iPort = $aConnectInfo[2];
|
||||
}
|
||||
else if (!$bUsePersistentConnection && ($iConnectInfoCount == 2))
|
||||
{
|
||||
$iPort = $aConnectInfo[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$iPort = 3306;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ class iTopMutex
|
||||
$sTlsCipher = $this->sDBTlsCipher;
|
||||
|
||||
$this->hDBLink = CMDBSource::GetMysqliInstance($sServer, $sUser, $sPwd, $sSource, $sTlsKey, $sTlsCert, $sTlsCA,
|
||||
$sTlsCaPath, $sTlsCipher, false, false);
|
||||
$sTlsCaPath, $sTlsCipher, false);
|
||||
|
||||
if (!$this->hDBLink)
|
||||
{
|
||||
|
||||
@@ -534,7 +534,7 @@ if (class_exists('ZipArchive')) // The setup must be able to start even if the "
|
||||
try
|
||||
{
|
||||
$oMysqli = CMDBSource::GetMysqliInstance($sServer, $sUser, $sPwd, $sSource, $sTlsKey, $sTlsCert,
|
||||
$sTlsCA, $sTlsCaPath, $sTlsCipher, true, false);
|
||||
$sTlsCA, $sTlsCaPath, $sTlsCipher, false);
|
||||
|
||||
if ($oMysqli->connect_errno)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user