Oracle 5.0 Reference Manual page 2636

Table of Contents

Advertisement

Mysqlnd replication and load balancing plugin (mysqlnd_ms)
Parameter
Example 20.281. Using a callback
{
"myapp": {
}
}
<?php
function pick_server($connected, $query, $masters, $slaves, $last_used_conn
{
static $slave_idx = 0;
static $num_slaves = NULL;
if (is_null($num_slaves))
$num_slaves = count($slaves);
/* default: fallback to the plugins build-in logic */
$ret = NULL;
printf("User has connected to '%s'...\n", $connected);
printf("... deciding where to run '%s'\n", $query);
$where = mysqlnd_ms_query_is_select($query);
switch ($where)
{
case MYSQLND_MS_QUERY_USE_MASTER:
printf("... using master\n");
$ret = $masters[0];
break;
case MYSQLND_MS_QUERY_USE_SLAVE:
/* SELECT or SQL hint for using slave */
if (stristr($query, "FROM table_on_slave_a_only"))
{
/* a table which is only on the first configured slave
printf("... access to table available only on slave A detected\n");
$ret = $slaves[0];
Description
mode is turned off, this will be set to
Otherwise it is set to
FALSE
Transaction detection is based on monitoring
the mysqlnd library call set_autocommit.
Monitoring is not possible before PHP 5.4.0.
Please, see
connection pooling and switching
concepts discussion for further details.
"master": {
"master_0": {
"host": "localhost"
}
},
"slave": {
"slave_0": {
"host": "192.168.2.27",
"port": "3306"
},
"slave_1": {
"host": "192.168.78.136",
"port": "3306"
}
},
"filters": {
"user": {
"callback": "pick_server"
}
}
2616
Version
.
TRUE
.
*/

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents