Set MYSQLI_OPT_CONNECT_TIMEOUT in mysqli
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 19 Jun 2014 20:20:26 +0000 (13:20 -0700)
committerBryanDavis <bdavis@wikimedia.org>
Fri, 20 Jun 2014 15:51:45 +0000 (15:51 +0000)
* There is no php.ini setting for this, and it is unclear how
  high the default is. The retry behavior of MediaWiki also
  makes little sense without knowing this value.
* Also removed the retry loop which will mostly result in
  giving up the position in some FIFO queue only to come
  back at the end of the line.

Change-Id: Id24f6635508ba87288a2e40f71d4e8016a1805b0

includes/db/DatabaseMysqli.php

index 8c9b06c..b8d5d79 100644 (file)
@@ -87,17 +87,12 @@ class DatabaseMysqli extends DatabaseMysqlBase {
                } else {
                        $mysqli->options( MYSQLI_SET_CHARSET_NAME, 'binary' );
                }
+               $mysqli->options( MYSQLI_OPT_CONNECT_TIMEOUT, 3 );
 
-               $numAttempts = 2;
-               for ( $i = 0; $i < $numAttempts; $i++ ) {
-                       if ( $i > 1 ) {
-                               usleep( 1000 );
-                       }
-                       if ( $mysqli->real_connect( $realServer, $this->mUser,
-                               $this->mPassword, $this->mDBname, $port, null, $connFlags )
-                       ) {
-                               return $mysqli;
-                       }
+               if ( $mysqli->real_connect( $realServer, $this->mUser,
+                       $this->mPassword, $this->mDBname, $port, null, $connFlags )
+               ) {
+                       return $mysqli;
                }
 
                return false;