[*] Installer : added timout to sql connection

This commit is contained in:
dMetzger
2012-08-07 12:32:40 +00:00
parent e39ce99efe
commit dcbb07649b
4 changed files with 14 additions and 7 deletions
+2 -2
View File
@@ -637,9 +637,9 @@ abstract class DbCore
* @param bool $engine * @param bool $engine
* @return int * @return int
*/ */
public static function checkConnection($server, $user, $pwd, $db, $new_db_link = true, $engine = null) public static function checkConnection($server, $user, $pwd, $db, $new_db_link = true, $engine = null, $timeout = 5)
{ {
return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $new_db_link, $engine)); return call_user_func_array(array(Db::getClass(), 'tryToConnect'), array($server, $user, $pwd, $db, $new_db_link, $engine, $timeout));
} }
/** /**
+9 -3
View File
@@ -161,10 +161,16 @@ class DbMySQLiCore extends Db
/** /**
* @see Db::checkConnection() * @see Db::checkConnection()
*/ */
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null) public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null, $timeout = 5)
{ {
$link = @new mysqli($server, $user, $pwd, $db); $link = mysqli_init();
if (mysqli_connect_error()) if (!$link)
return -1;
if (!$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout))
return 1;
if (!$link->real_connect($server, $user, $pwd, $db);
return (mysqli_connect_errno() == 1049) ? 2 : 1; return (mysqli_connect_errno() == 1049) ? 2 : 1;
if (strtolower($engine) == 'innodb') if (strtolower($engine) == 'innodb')
+2 -2
View File
@@ -179,11 +179,11 @@ class DbPDOCore extends Db
/** /**
* @see Db::checkConnection() * @see Db::checkConnection()
*/ */
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null) public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null, $timeout = 5)
{ {
try try
{ {
$link = @new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd); $link = @new PDO('mysql:dbname='.$db.';host='.$server, $user, $pwd, array(PDO::ATTR_TIMEOUT => $timeout));
} }
catch (PDOException $e) catch (PDOException $e)
{ {
+1
View File
@@ -156,6 +156,7 @@ class MySQLCore extends Db
*/ */
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null) public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null)
{ {
ini_set('mysql.connect_timeout', $timeout);
if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink)) if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink))
return 1; return 1;
if (!@mysql_select_db($db, $link)) if (!@mysql_select_db($db, $link))