Ticket #5932: check-connection.diff

File check-connection.diff, 2.2 KB (added by pento, 10 months ago)
  • wp-includes/wp-db.php

     
    147147         * @var array 
    148148         */ 
    149149        var $queries; 
     150         
     151        /** 
     152         * The number of times to retry reconnecting before dying. 
     153         * 
     154         * @since 3.5.0 
     155         * @access protected 
     156         * @see wpdb::check_connection() 
     157         * @var int 
     158         */ 
     159        protected $reconnect_retries = 5; 
    150160 
    151161        /** 
    152162         * WordPress table prefix 
     
    10661076        } 
    10671077 
    10681078        /** 
     1079         * Check that the connection to the database is still up. If not, try to reconnect. 
     1080         * 
     1081         * @since 3.5.0 
     1082         */ 
     1083        function check_connection() { 
     1084                $tries = 1; 
     1085                while ( ! mysql_ping( $this->dbh ) ) { 
     1086                        if ( WP_DEBUG ) { 
     1087                                $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); 
     1088                        } else { 
     1089                                $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); 
     1090                        } 
     1091 
     1092                        if ( $this->dbh ) { 
     1093                                $this->set_charset( $this->dbh ); 
     1094                                $this->select( $this->dbname, $this->dbh ); 
     1095 
     1096                                return true; 
     1097                        } 
     1098                                 
     1099                        $tries++; 
     1100                         
     1101                        if ( $tries >= $this->reconnect_retries ) { 
     1102                                $this->bail( sprintf( __( " 
     1103<h1>Error reconnecting to the database</h1> 
     1104<p>This means that we lost our connection to the database server at <code>%s</code>, your host's database server may be down.</p> 
     1105<ul> 
     1106        <li>Are you sure that the database server is running?</li> 
     1107        <li>Are you sure that the database server is not under particularly heavy load?</li> 
     1108</ul> 
     1109<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p> 
     1110" ), htmlspecialchars( $this->dbhost, ENT_QUOTES ) ), 'db_connect_fail' ); 
     1111 
     1112                                return false; 
     1113                        } 
     1114                } 
     1115                 
     1116                return true; 
     1117        } 
     1118 
     1119 
     1120        /** 
    10691121         * Perform a MySQL database query, using current database connection. 
    10701122         * 
    10711123         * More information can be found on the codex page. 
     
    10791131                if ( ! $this->ready ) 
    10801132                        return false; 
    10811133 
     1134                if( ! $this->check_connection() ) 
     1135                        return false; 
     1136 
    10821137                // some queries are made before the plugins have been loaded, and thus cannot be filtered with this method 
    10831138                $query = apply_filters( 'query', $query ); 
    10841139