@@ -1052,10 +1052,7 @@ public function db_connect( $query = '' ) {
10521052
10531053 $ this ->timer_start ();
10541054
1055- // Maybe check TCP responsiveness
1056- $ tcp = ! empty ( $ this ->check_tcp_responsiveness )
1057- ? $ this ->check_tcp_responsiveness ( $ host , $ port , $ timeout )
1058- : null ;
1055+ $ tcp = $ this ->check_tcp_responsiveness ( $ host , $ port , $ timeout );
10591056
10601057 // Connect if necessary or possible
10611058 if (
@@ -1272,6 +1269,7 @@ protected function increment_db_connection( $connection = 0, $name = '' ) {
12721269 * @return bool|mysqli|resource
12731270 */
12741271 protected function single_db_connect ( $ dbhname , $ host , $ user , $ password ) {
1272+ $ tcp_cache_key = $ host ;
12751273 $ this ->is_mysql = true ;
12761274
12771275 // Check client flags
@@ -1338,6 +1336,8 @@ protected function single_db_connect( $dbhname, $host, $user, $password ) {
13381336 if ( ! empty ( $ this ->dbhs [ $ dbhname ]->connect_errno ) ) {
13391337 $ this ->dbhs [ $ dbhname ] = false ;
13401338
1339+ $ this ->tcp_cache_set ( $ tcp_cache_key , 'down ' );
1340+
13411341 return false ;
13421342 }
13431343
@@ -2310,6 +2310,11 @@ public function check_tcp_responsiveness( $host, $port, $float_timeout ) {
23102310 return false ;
23112311 }
23122312
2313+ if ( empty ( $ this ->check_tcp_responsiveness ) ) {
2314+ $ this ->tcp_responsive = true ;
2315+ return true ;
2316+ }
2317+
23132318 // Defaults
23142319 $ errno = 0 ;
23152320 $ errstr = '' ;
@@ -2324,6 +2329,7 @@ public function check_tcp_responsiveness( $host, $port, $float_timeout ) {
23242329 // No socket
23252330 if ( false === $ socket ) {
23262331 $ this ->tcp_cache_set ( $ cache_key , 'down ' );
2332+ $ this ->tcp_responsive = false ;
23272333
23282334 return "[ > {$ float_timeout } ] ( {$ errno }) ' {$ errstr }' " ;
23292335 }
@@ -2334,6 +2340,7 @@ public function check_tcp_responsiveness( $host, $port, $float_timeout ) {
23342340
23352341 // Using API
23362342 $ this ->tcp_cache_set ( $ cache_key , 'up ' );
2343+ $ this ->tcp_responsive = true ;
23372344
23382345 return true ;
23392346 }
0 commit comments