wp-includes/wp-db.php
/**
	 * Checks that the connection to the database is still up. If not, try to reconnect.
	 *
	 * If this function is unable to reconnect, it will forcibly die, or if after the
	 * the {@see 'template_redirect'} hook has been fired, return false instead.
	 *
	 * If $allow_bail is false, the lack of database connection will need
	 * to be handled manually.
	 *
	 * @since 3.9.0
	 *
	 * @param bool $allow_bail Optional. Allows the function to bail. Default true.
	 * @return bool|void True if the connection is up.
	 */
Checks that the connection to the database is still up. If not, try to reconnect.
If this function is unable to reconnect, it will forcibly die, or if after the
the  'template_redirect' hook has been fired, return false instead.

If $allow_bail is false, the lack of database connection will need
to be handled manually.



@param bool $allow_bail Optional. Allows the function to bail. Default true.
@return bool|void True if the connection is up.
Checks that the connection to the database is still up . If not try to reconnect . If this function is unable to reconnect it will forcibly die or if after the the ' template_redirect ' hook has been fired return false instead . If $allow_bail is false the lack of database connection will need to be handled manually . @param bool $allow_bail Optional . Allows the function to bail . Default true . @return bool|void True if the connection is up .
public function check_connection( $allow_bail = true ) {
		if ( $this->use_mysqli ) {
			if ( ! empty( $this->dbh ) && mysqli_ping( $this->dbh ) ) {
				return true;
			}
		} else {
			if ( ! empty( $this->dbh ) && mysql_ping( $this->dbh ) ) {
				return true;
			}
		}
		$error_reporting = false;
		if ( WP_DEBUG ) {
			$error_reporting = error_reporting();
			error_reporting( $error_reporting & ~E_WARNING );
		}
		for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) {
			if ( $this->reconnect_retries === $tries && WP_DEBUG ) {
				error_reporting( $error_reporting );
			}
			if ( $this->db_connect( false ) ) {
				if ( $error_reporting ) {
					error_reporting( $error_reporting );
				}
				return true;
			}
			sleep( 1 );
		}
		if ( did_action( 'template_redirect' ) ) {
			return false;
		}
		if ( ! $allow_bail ) {
			return false;
		}
		wp_load_translations_early();
		$message = '<h1>' . __( 'Error reconnecting to the database' ) . "</h1>\n";
		$message .= '<p>' . sprintf(
			__( 'This means that we lost contact with the database server at %s. This could mean your host&#8217;s database server is down.' ),
			'<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
		) . "</p>\n";
		$message .= "<ul>\n";
		$message .= '<li>' . __( 'Are you sure that the database server is running?' ) . "</li>\n";
		$message .= '<li>' . __( 'Are you sure that the database server is not under particularly heavy load?' ) . "</li>\n";
		$message .= "</ul>\n";
		$message .= '<p>' . sprintf(
			__( 'If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
			__( 'https://wordpress.org/support/' )
		) . "</p>\n";
		$this->bail( $message, 'db_connect_fail' );
		dead_db();
	}
public function check_connection ( $ allow_bail = true ) { if ( $ this -> use_mysqli ) { if ( ! empty ( $ this -> dbh ) && mysqli_ping ( $ this -> dbh ) ) { return true ; } } else { if ( ! empty ( $ this -> dbh ) && mysql_ping ( $ this -> dbh ) ) { return true ; } } $ error_reporting = false ; if ( WP_DEBUG ) { $ error_reporting = error_reporting ( ) ; error_reporting ( $ error_reporting & ~ E_WARNING ) ; } for ( $ tries = 1 ; $ tries <= $ this -> reconnect_retries ; $ tries ++ ) { if ( $ this -> reconnect_retries === $ tries && WP_DEBUG ) { error_reporting ( $ error_reporting ) ; } if ( $ this -> db_connect ( false ) ) { if ( $ error_reporting ) { error_reporting ( $ error_reporting ) ; } return true ; } sleep ( 1 ) ; } if ( did_action ( 'template_redirect' ) ) { return false ; } if ( ! $ allow_bail ) { return false ; } wp_load_translations_early ( ) ; $ message = '<h1>' . __ ( 'Error reconnecting to the database' ) . " </h1> \n " ; $ message .= '<p>' . sprintf ( __ ( 'This means that we lost contact with the database server at %s. This could mean your host&#8217;s database server is down.' ) , '<code>' . htmlspecialchars ( $ this -> dbhost , ENT_QUOTES ) . '</code>' ) . " </p> \n " ; $ message .= " <ul> \n " ; $ message .= '<li>' . __ ( 'Are you sure that the database server is running?' ) . " </li> \n " ; $ message .= '<li>' . __ ( 'Are you sure that the database server is not under particularly heavy load?' ) . " </li> \n " ; $ message .= " </ul> \n " ; $ message .= '<p>' . sprintf ( __ ( 'If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ) , __ ( 'https://wordpress.org/support/' ) ) . " </p> \n " ; $ this -> bail ( $ message , 'db_connect_fail' ) ; dead_db ( ) ; }
Checks that the connection to the database is still up.
Checks that the connection to the database is still up .
// Disable warnings, as we don't want to see a multitude of "unable to connect" messages // On the last try, re-enable warnings. We want to see a single instance of the // "unable to connect" message on the bail() screen, if it appears. // If template_redirect has already happened, it's too late for wp_die()/dead_db(). // Let's just return and hope for the best. /* translators: %s: database host */ /* translators: %s: support forums URL */ // We weren't able to reconnect, so we better bail. // Call dead_db() if bail didn't die, because this database is no more. It has ceased to be (at least temporarily).