Oracle 5.0 Reference Manual page 2599

Table of Contents

Advertisement

$attempts = 0;
do {
/* check if slave has the table */
if ($res = $mysqli->query("SELECT id FROM test")) {
break;
} else if ($mysqli->errno) {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
/* wait for slave to catch up */
usleep(200000);
} while ($attempts++ < 10);
assert($res);
/* Query has been run on a slave, result is in the cache */
var_dump($res->fetch_assoc());
/* Served from cache */
if (!($res = $mysqli->query("SELECT id FROM test")))
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
var_dump($res->fetch_assoc());
/* Update on master */
if (!$mysqli->query("UPDATE test SET id = 2"))
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
/* Read your writes */
if (false == mysqlnd_ms_set_qos($mysqli, MYSQLND_MS_QOS_CONSISTENCY_SESSION)) {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
/* Fetch latest data */
if (!($res = $mysqli->query("SELECT id FROM test")))
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
var_dump($res->fetch_assoc());
?>
The quality of service can be changed at any time to avoid further cache usage. If needed, you can
switch to read your writes (session consistency). In that case, the cache will not be used and fresh data
is read.
20.7.6.4.9. Failover
Copyright 1997-2012 the PHP Documentation Group. [2230]
By default, the plugin does not attempt to fail over if connecting to a host fails. This prevents pitfalls
related to
connection
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. Because
the quickstart. Instead, details are given in the concepts section below.
Example 20.250. Manual failover, automatic optional
{
"myapp": {
"master": {
},
Mysqlnd replication and load balancing plugin (mysqlnd_ms)
state. It is recommended to manually handle connection errors in a way similar to
"master_0": {
"host": "localhost",
"socket": "\/tmp\/mysql.sock"
}
automatic failover
is not fool-proof, it is not discussed in
2579

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents