IT. Expert System.

PHP

Failover


Failover

By default, the plugin does not attempt to fail over if connecting to a host fails. This prevents pitfalls related to connection state. It is recommended to manually handle connection errors in a way similar to a failed transaction. You should catch the error, rebuild the connection state and rerun your query as shown below.

If connection state is no issue to you, you can alternatively enable automatic and silent failover. Depending on the configuration, the automatic and silent failover will either attempt to fail over to the master before issuing and error or, try to connect to other slaves, given the query allowes for it, before attempting to connect to a master.

Example #1 Manual failover, automatic optional

{  "myapp": {   "master": {    "master_0": {     "host": "localhost",     "socket": "\/tmp\/mysql.sock"    }   },   "slave": {    "slave_0": {     "host": "simulate_slave_failure",     "port": "0"    },    "slave_1": {     "host": "127.0.0.1",     "port": 3311    }   },  "filters": { "roundrobin": [] }  } }

Example #2 Manual failover

<?php
$mysqli 
= new mysqli("myapp""username""password""database");
if (!
$mysqli)
  
/* Of course, your error handling is nicer... */
  
die(sprintf("[%d] %s\n"mysqli_connect_errno(), mysqli_connect_error()));

$sql "SELECT 1 FROM DUAL";

/* error handling as it should be done regardless of the plugin */
if (!($res $link->query($sql))) {
  
/* plugin specific: check for connection error */
  
switch ($link->errno) {
    case 
2002:
    case 
2003:
    case 
2005:
      
printf("Connection error - trying next slave!\n");
      
/* load balancer will pick next slave */
      
$res $link->query($sql);
      break;
    default:
      
/* no connecion error, failover is unlikely to help */
      
die(sprintf("SQL error: [%d] %s"$link->errno$link->error));
      break;
  }
}
if (
$res) {
  
var_dump($res->fetch_assoc());
}
?>



Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 463 / 158691902. Delta: 0.03589 с