Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 10760

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Plugin configuration file (&gt;=1.1.x)</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqlnd-ms.configuration.html">Runtime Configuration</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqlnd-ms.constants.html">Predefined Constants</a></div>
 <div class="up"><a href="mysqlnd-ms.setup.html">Installing/Configuring</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mysqlnd-ms.plugin-ini-json" class="section">
  <h2 class="title">Plugin configuration file (&gt;=1.1.x)</h2>

  <p class="para">
   The following documentation applies to PECL/mysqlnd_ms &gt;= 1.1.0-beta.
   It is not valid for prior versions. For documentation covering earlier
   versions, see the configuration documentation
   for <a href="mysqlnd-ms.plugin-ini-json.html#mysqlnd-ms.plugin-ini-v1" class="link">mysqlnd_ms 1.0.x and below</a>.
  </p>

  <div class="section" id="mysqlnd-ms.plugin-ini-json-introduction">
   <h2 class="title">Introduction</h2>


   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <strong>Changelog: Feature was added in PECL/mysqlnd_ms 1.1.0-beta</strong><br />
    <p class="para">
     The below description applies to PECL/mysqlnd_ms &gt;= 1.1.0-beta.
     It is not valid for prior versions.
    </p>
   </p></blockquote>

  <p class="para">
   The plugin uses its own configuration file. The configuration file
   holds information about the MySQL replication master server,
   the MySQL replication slave servers, the server pick (load balancing) policy,
   the failover strategy, and the use of lazy connections.
  </p>
  <p class="para">
   The plugin loads its configuration file at the beginning of a web request.
   It is then cached in memory and used for the duration of the web request.
   This way, there is no need to restart PHP after deploying the configuration
   file. Configuration file changes will become active almost instantly.
  </p>
  <p class="para">
   The PHP configuration directive
   <a href="mysqlnd-ms.configuration.html#ini.mysqlnd-ms.config-file" class="link"><em>mysqlnd_ms.config_file</em></a>
   is used to set the plugins configuration file. Please note, that
   the PHP configuration directive may not be evaluated for every web request.
   Therefore, changing the plugins configuration file name or location may
   require a PHP restart. However, no restart is required to read changes if
   an already existing plugin configuration file is updated.
  </p>
  <p class="para">
   Using and parsing <acronym title="JavaScript Object Notation">JSON</acronym> is efficient, and using <acronym title="JavaScript Object Notation">JSON</acronym>
   makes it easier to express hierarchical data structures than the standard
   <var class="filename">php.ini</var> format.
  </p>
  <p class="para">
   <div class="example" id="example-2277">
    <p><strong>Example #1 Converting a PHP array (hash) into JSON format</strong></p>
    <div class="example-contents"><p>
     Or alternatively, a developer may be more familiar with the PHP <span class="type"><a href="language.types.array.html" class="type array">array</a></span>
     syntax, and prefer it. This example demonstrates how a developer might convert a
     PHP array to <acronym title="JavaScript Object Notation">JSON</acronym>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$config&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;</span><span style="color: #DD0000">"myapp"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"master"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"master_0"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"host"&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"socket"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"/tmp/mysql.sock"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"slave"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(),<br />&nbsp;&nbsp;),<br />);<br /><br /></span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysqlnd_ms.ini"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">json_encode</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">JSON_PRETTY_PRINT</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysqlnd_ms.ini&nbsp;file&nbsp;created...\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Dumping&nbsp;file&nbsp;contents...\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">str_repeat</span><span style="color: #007700">(</span><span style="color: #DD0000">"-"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">80</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysqlnd_ms.ini"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">str_repeat</span><span style="color: #007700">(</span><span style="color: #DD0000">"-"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">80</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
mysqlnd_ms.ini file created...
Dumping file contents...
--------------------------------------------------------------------------------
{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;,
                &quot;socket&quot;: &quot;\/tmp\/mysql.sock&quot;
            }
        },
        &quot;slave&quot;: [

        ]
    }
}
--------------------------------------------------------------------------------
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   A plugin configuration file consists of one or more sections. Sections
   are represented by the top-level object properties of the
   object encoded in the <acronym title="JavaScript Object Notation">JSON</acronym> file. Sections could also
   be called <em class="emphasis">configuration names</em>.
  </p>
  <p class="para">
   Applications reference sections by their name. Applications use section names
   as the host (server) parameter to the various connect methods of the
   <a href="ref.mysqli.html" class="link">mysqli</a>,
   <a href="ref.mysql.html" class="link">mysql</a> and
   <a href="ref.pdo-mysql.html" class="link">PDO_MYSQL</a> extensions. Upon connect,
   the <a href="book.mysqlnd.html" class="link">mysqlnd</a> plugin compares the hostname
   with all of the section names from the plugin configuration file. If the hostname and
   section name match, then the plugin will load the settings for that section.
  </p>
  <p class="para" id="mysqlnd-ms.plugin-ini-json.using-section">
   <div class="example" id="example-2278">
    <p><strong>Example #2 Using section names example</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.2.27&quot;
            },
            &quot;slave_1&quot;: {
                &quot;host&quot;: &quot;192.168.2.27&quot;,
                &quot;port&quot;: 3306
            }
        }
    },
    &quot;localhost&quot;: {
        &quot;master&quot;: [
            {
                &quot;host&quot;: &quot;localhost&quot;,
                &quot;socket&quot;: &quot;\/path\/to\/mysql.sock&quot;
            }
        ],
        &quot;slave&quot;: [
            {
                &quot;host&quot;: &quot;192.168.3.24&quot;,
                &quot;port&quot;: &quot;3305&quot;
            },
            {
                &quot;host&quot;: &quot;192.168.3.65&quot;,
                &quot;port&quot;: &quot;3309&quot;
            }
        ]
    }
}</pre>
</div>
    </div>

    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;All&nbsp;of&nbsp;the&nbsp;following&nbsp;connections&nbsp;will&nbsp;be&nbsp;load&nbsp;balanced&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pdo&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysql:host=myapp;dbname=database'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'username'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'password'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Section names are strings. It is valid to use a section name such as
   <em>192.168.2.1</em>, <em>127.0.0.1</em> or
   <em>localhost</em>. If, for example, an application
   connects to <em>localhost</em> and a plugin
   configuration section <em>localhost</em> exists, the
   semantics of the connect operation are changed. The application will
   no longer only use the MySQL server running on the host
   <em>localhost</em>, but the plugin will start to load balance
   MySQL queries following the rules from the <em>localhost</em>
   configuration section. This way you can load balance queries from
   an application without changing the applications source code.
   Please keep in mind, that such a configuration may not contribute
   to overall readability of your applications source code. Using section names
   that can be mixed up with host names should be seen as a last resort.
  </p>
  <p class="para" id="mysqlnd-ms.plugin-ini-json.server-list-syntax">
   Each configuration section contains, at a minimum, a list of master servers
   and a list of slave servers. The master list is configured with the keyword
   <em>master</em>, while the slave list is configured with the
   <em>slave</em> keyword. Failing to provide a slave list will result
   in a fatal <strong><code>E_ERROR</code></strong> level error, although a slave list
   may be empty. It is possible to allow no slaves. However, this is only recommended
   with synchronous clusters, please see also
   <a href="mysqlnd-ms.supportedclusters.html" class="link">supported clusters</a>.
   The main part of the documentation focusses on the use
   of asynchronous MySQL replication clusters.
  </p>
  <p class="para">
   The master and slave server lists can be optionally indexed by symbolic
   names for the servers they describe. Alternatively, an array of descriptions
   for slave and master servers may be used.
  </p>
  <p class="para">
   <div class="example" id="example-2279">
    <p><strong>Example #3 List of anonymous slaves</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">&quot;slave&quot;: [
    {
        &quot;host&quot;: &quot;192.168.3.24&quot;,
        &quot;port&quot;: &quot;3305&quot;
    },
    {
        &quot;host&quot;: &quot;192.168.3.65&quot;,
        &quot;port&quot;: &quot;3309&quot;
    }
]</pre>
</div>
    </div>

   </div>
  </p>
  <p class="para">
   An anonymous server list is encoded by the <em>JSON array</em> type.
   Optionally, symbolic names may be used for indexing the slave or master servers
   of a server list, and done so using the <em>JSON object</em> type.
  </p>
  <p class="para">
   <div class="example" id="example-2280">
    <p><strong>Example #4 Master list using symbolic names</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">&quot;master&quot;: {
    &quot;master_0&quot;: {
        &quot;host&quot;: &quot;localhost&quot;
    }
}</pre>
</div>
    </div>

   </div>
  </p>
  <p class="para">
   It is recommended to index the server lists with symbolic server names.
   The alias names will be shown in error messages.
  </p>
  <p class="para">
   The order of servers is preserved and taken into account by mysqlnd_ms.
   If, for example, you configure round robin load balancing strategy, the
   first <em>SELECT</em> statement will be executed on the
   slave that appears first in the slave server list.
  </p>
  <p class="para">
   A configured server can be described with the <em>host</em>,
   <em>port</em>, <em>socket</em>, <em>db</em>,
   <em>user</em>, <em>password</em> and <em>connect_flags</em>.
   It is mandatory to set the database server host using the <em>host</em>
   keyword. All other settings are optional.
  </p>
  <p class="para">
   <div class="example" id="example-2281">
    <p><strong>Example #5 Keywords to configure a server</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;db_server_host&quot;,
                &quot;port&quot;: &quot;db_server_port&quot;,
                &quot;socket&quot;: &quot;db_server_socket&quot;,
                &quot;db&quot;: &quot;database_resp_schema&quot;,
                &quot;user&quot;: &quot;user&quot;,
                &quot;password&quot;: &quot;password&quot;,
                &quot;connect_flags&quot;: 0
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;db_server_host&quot;,
                &quot;port&quot;: &quot;db_server_port&quot;,
                &quot;socket&quot;: &quot;db_server_socket&quot;
            }
        }
    }
}</pre>
</div>
    </div>

   </div>
  </p>
  <p class="para">
   If a setting is omitted, the plugin will use the value provided by the user
   API call used to open a connection. Please, see the
   <a href="mysqlnd-ms.plugin-ini-json.html#mysqlnd-ms.plugin-ini-json.using-section" class="link">using section names example</a> above.
  </p>
  <p class="para">
   The configuration file format has been changed in version 1.1.0-beta to allow for
   chained filters. Filters are responsible for filtering the configured list of
   servers to identify a server for execution of a given statement.
   Filters are configured with the <em>filter</em> keyword. Filters
   are executed by mysqlnd_ms in the order of their appearance.
   Defining filters is optional. A configuration section in the plugins
   configuration file does not need to have a <em>filters</em> entry.
  </p>
  <p class="para">
   Filters replace the
   <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config.pick" class="link"><em>pick[]</em></a>
   setting from prior versions. The new <em>random</em> and
   <em>roundrobin</em> provide the same functionality.
  </p>
  <p class="para">
   <div class="example" id="example-2282">
    <p><strong>Example #6 New <em>roundrobin</em> filter, old functionality</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            },
            &quot;slave_1&quot;: {
                &quot;host&quot;: &quot;192.168.78.137&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;filters&quot;: {
            &quot;roundrobin&quot;: [

            ]
        }
    }
}</pre>
</div>
    </div>

   </div>
  </p>
  <p class="para">
   The function
   <span class="function"><a href="function.mysqlnd-ms-set-user-pick-server.html" class="function">mysqlnd_ms_set_user_pick_server()</a></span>
   has been removed. Setting a callback is now done with the <em>user</em>
   filter. Some filters accept parameters. The <em>user</em> filter
   requires and accepts a mandatory <em>callback</em> parameter
   to set the callback previously set through the function <span class="function"><a href="function.mysqlnd-ms-set-user-pick-server.html" class="function">mysqlnd_ms_set_user_pick_server()</a></span>.
   <div class="example" id="example-2283">
    <p><strong>Example #7 The <em>user</em> filter replaces <span class="function"><a href="function.mysqlnd-ms-set-user-pick-server.html" class="function">mysqlnd_ms_set_user_pick_server()</a></span></strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">&quot;filters&quot;: {
    &quot;user&quot;: {
        &quot;callback&quot;: &quot;pick_server&quot;
    }
}</pre>
</div>
    </div>

   </div>
  </p>
  <p class="para" id="mysqlnd-ms.plugin-ini-json.debug_config">
   The validity of the configuration file is checked both when reading the
   configuration file and later when establishing a connection. The configuration
   file is read during PHP request startup. At this early stage a PHP extension
   may not display error messages properly. In the worst case, no error
   is shown and a connection attempt fails without an adequate error message.
   This problem has been cured in version 1.5.0.
  </p>
  <p class="para">
   <div class="example" id="example-2284">
    <p><strong>Example #8 Common error message in case of configuration file issues (upto version 1.5.0)</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Warning: mysqli::mysqli(): (mysqlnd_ms) (mysqlnd_ms) Failed to parse config file [s1.json]. Please, verify the JSON in Command line code

Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in Command line code on line 1

Warning: mysqli::query(): Couldn&#039;t fetch mysqli in Command line code on line 1

Fatal error: Call to a member function fetch_assoc() on a non-object in Command line code on line 1
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   Since version 1.5.0 startup errors are additionally buffered and emitted when
   a connection attempt is made. Use the configuration directive
   <a href="mysqlnd-ms.configuration.html#ini.mysqlnd-ms.force-config-usage" class="link"><em>mysqlnd_ms.force_config_usage</em></a>
   to set the error type used to display buffered errors. By default an error
   of type <em>E_WARNING</em> will be emitted.
 </p>
  <p class="para">
   <div class="example" id="example-2285">
    <p><strong>Example #9 Improved configuration file validation since 1.5.0</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Warning: mysqli::mysqli(): (mysqlnd_ms) (mysqlnd_ms) Failed to parse config file [s1.json]. Please, verify the JSON in Command line code on line 1
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   It can be useful to set <a href="mysqlnd-ms.configuration.html#ini.mysqlnd-ms.force-config-usage" class="link"><em>mysqlnd_ms.force_config_usage = 1</em></a>
   when debugging potential configuration file errors. This will not only turn the
   type of buffered startup errors into <em>E_RECOVERABLE_ERROR</em> but also
   help detecting misspelled section names.
  </p>
  <p class="para">
   <div class="example" id="example-2286">
    <p><strong>Example #10 Possibly more precise error due to <em>mysqlnd_ms.force_config_usage=1</em></strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">mysqlnd_ms.force_config_usage=1</pre>
</div>
    </div>

     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"invalid_section"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

<div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Warning: mysqli::mysqli(): (mysqlnd_ms) Exclusive usage of configuration enforced but did not find the correct INI file section (invalid_section) in Command line code on line 1 line 1
</pre></div>
    </div>

   </div>
  </p>
  </div>

  <div class="section" id="mysqlnd-ms.plugin-ini-json-reference">
   <h2 class="title">Configuration Directives</h2>

  <p class="para">
   Here is a short explanation of the configuration directives that can be used.
  </p>
  <p class="para">
  <dl>

   
     <dt id="ini.mysqlnd-ms-plugin-config-v2.master">
      <code class="parameter">master</code>
      <span class="type"><span class="type array or object">array or object</span></span>
     </dt>

     <dd>

      <p class="para">
       List of MySQL replication master servers. The list of either
       of the <em>JSON type array</em> to declare an anonymous list
       of servers or of the <em>JSON type object</em>. Please,
       see <a href="mysqlnd-ms.plugin-ini-json.html#mysqlnd-ms.plugin-ini-json.server-list-syntax" class="link">above</a>
       for examples.
      </p>
      <p class="para">
       Setting at least one master server is mandatory. The plugin will issue an
       error of type <em>E_ERROR</em> if the user has failed to
       provide a master server list for a configuration section.
       The fatal error may read
       <em>(mysqlnd_ms) Section [master] doesn&#039;t exist for host
       [name_of_a_config_section] in %s on line %d</em>.
      </p>
      <p class="para">
       A server is described with
       the <em>host</em>, <em>port</em>,
       <em>socket</em>, <em>db</em>,
       <em>user</em>, <em>password</em> and
       <em>connect_flags</em>. It is mandatory to
       provide at  a value for <em>host</em>. If any of the
       other values is not given, it will be taken from the user
       API connect call, please, see also:
       <a href="mysqlnd-ms.plugin-ini-json.html#mysqlnd-ms.plugin-ini-json.using-section" class="link">using section names example</a>.
      </p>
      <p class="para" id="mysqlnd-ms.plugin-ini-json.server-config-keywords">
       Table of server configuration keywords.
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
           <td>
             <em>host</em>
           </td>
           <td>
            <p class="para">
             Database server host. This is a mandatory setting.
             Failing to provide, will cause an error of type <em>E_RECOVERABLE_ERROR</em>
             when the plugin tries to connect to the server. The error message may
             read <em>(mysqlnd_ms) Cannot find [host] in
             [%s] section in config in %s on line %d</em>.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>port</em>
           </td>
           <td>
            <p class="para">
              Database server TCP/IP port.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>socket</em>
           </td>
           <td>
            <p class="para">
              Database server Unix domain socket.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>db</em>
           </td>
           <td>
            <p class="para">
              Database (schemata).
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>user</em>
           </td>
           <td>
            <p class="para">
              MySQL database user.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>password</em>
           </td>
           <td>
            <p class="para">
              MySQL database user password.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>connect_flags</em>
           </td>
           <td>
            <p class="para">
              Connection flags.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

        </tbody>
       
      </table>

      <p class="para">
       The plugin supports using only one master server. An experimental
       setting exists to enable multi-master support. The details are
       not documented. The setting is meant for development only.
      </p>
     </dd>

    
    
    <dt id="ini.mysqlnd-ms-plugin-config-v2.slave">
      <code class="parameter">slave</code>
      <span class="type"><span class="type array or object">array or object</span></span>
     </dt>

     <dd>

      <p class="para">
       List of one or more MySQL replication slave servers. The syntax is
       identical to setting master servers, please, see
       <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config-v2.master" class="link"><em>master</em></a>
       above for details.
      </p>
      <p class="para">
       The plugin supports using one or more slave servers.
      </p>
      <p class="para">
       Setting a list of slave servers is mandatory. The plugin will report
       an error of the type <em>E_ERROR</em> if <em>slave</em>
       is not given for a configuration section. The fatal error message may read
       <em>(mysqlnd_ms) Section [slave] doesn&#039;t exist for host [%s] in %s on line %d</em>.
       Note, that it is valid to use an empty slave server list.
       The error has been introduced to prevent accidently setting no slaves by
       forgetting about the <em>slave</em> setting.
       A master-only setup is still possible using an empty slave server list.
      </p>
      <p class="para">
       If an empty slave list is configured and an attempt is made to
       execute a statement on a slave the plugin may emit a warning like
       <em>mysqlnd_ms) Couldn&#039;t find the appropriate slave connection.
       0 slaves to choose from.</em> upon statement execution.
       It is possible that another warning follows such as
       <em>(mysqlnd_ms) No connection selected by the last filter</em>.
      </p>
     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.gtid">
      <code class="parameter">global_transaction_id_injection</code>
      <span class="type"><span class="type array or object">array or object</span></span>
     </dt>

     <dd>

      <p class="para">
       Global transaction identifier configuration related to both
       the use of the server built-in global transaction ID feature and
       the client-side emulation.
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>
            <em>fetch_last_gtid</em>
          </td>
          <td>
           <p class="para">
            SQL statement for accessing the latest global transaction identifier.
            The SQL statement is run if the plugin needs to know the most recent
            global transaction identifier. This can be the case, for example, when checking
            MySQL Replication slave status.
            Also used with <span class="function"><a href="function.mysqlnd-ms-get-last-gtid.html" class="function">mysqlnd_ms_get_last_gtid()</a></span>.
           </p>
          </td>
          <td>Since 1.2.0.</td>
         </tr>

         <tr>
          <td>
            <em>check_for_gtid</em>
          </td>
          <td>
           <p class="para">
            SQL statement for checking if a replica has replicated
            all transactions up to and including ones searched for. The
            SQL statement is run when searching for replicas which can offer
            a higher level of consistency than eventual consistency.
            The statement must contain a placeholder <em>#GTID</em>
            which is to be replaced with the global transaction identifier searched
            for by the plugin. Please, check the
            <a href="mysqlnd-ms.quickstart.gtid.html" class="link">quickstart</a> for examples.
           </p>
          </td>
          <td>Since 1.2.0.</td>
         </tr>

         <tr>
          <td>
            <em>report_errors</em>
          </td>
          <td>
           <p class="para">
            Whether to emit an error of type warning if an issue occurs while
            executing any of the configured SQL statements.
           </p>
          </td>
          <td>Since 1.2.0.</td>
         </tr>

         <tr>
          <td>
           <em>on_commit</em>
          </td>
          <td>
           <p class="para">
            Client-side global transaction ID emulation only. SQL statement
            to run when a transaction finished to update the global transaction
            identifier sequence number on the master. Please, see the
            <a href="mysqlnd-ms.quickstart.gtid.html" class="link">quickstart</a> for examples.
           </p>
          </td>
          <td>Since 1.2.0.</td>
          </tr>

         <tr>
          <td>
           <em>wait_for_gtid_timeout</em>
          </td>
          <td>
           <p class="para">
            Instructs the plugin to wait up to <em>wait_for_gtid_timeout</em>
            seconds for a slave to catch up when searching for slaves that can
            deliver session consistency. The setting limits the time spend for
            polling the slave status. If polling the status takes very long, the total
            clock time spend waiting may exceed <em>wait_for_gtid_timeout</em>.
            The plugin calls <em>sleep(1)</em> to sleep one second between
            each two polls.
           </p>
           <p class="para">
            The setting can be used both with the plugins client-side emulation
            and the server-side global transaction identifier feature of MySQL 5.6.
           </p>
           <p class="para">
            Waiting for a slave to replicate a certain GTID needed for session
            consistency also means throttling the client. By throttling the
            client the write load on the master is reduced indirectly. A
            primary copy based replication system, such as MySQL Replication,
            is given more time to reach a consistent state. This can be desired,
            for example, to increase the number of data copies for
            high availability considerations or to prevent the master from being
            overloaded.
           </p>
          </td>
          <td>Since 1.4.0.</td>
          </tr>

         </tbody>
        
       </table>

     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.fabric">
      <code class="parameter">fabric</code>
      <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
        MySQL Fabric related settings. If the plugin is used together with MySQL
        Fabric, then the plugins configuration file no longer contains lists of MySQL servers.
        Instead, the plugin will ask MySQL Fabric which list of servers to use to
        perform a certain task.
      </p>
      <p class="para">
        A minimum plugin configuration for use with MySQL Fabric contains a list
        of one or more MySQL Fabric hosts that the plugin can query. If more
        than one MySQL Fabric host is  configured, the plugin will use a roundrobin
        strategy to choose among them. Other strategies are currently not available.
      </p>
      <p class="para">
       <div class="example" id="example-2287">
        <p><strong>Example #11 Minimum pluging configuration for use with MySQL Fabric</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;fabric&quot;: {
            &quot;hosts&quot;: [
                {
                    &quot;host&quot; : &quot;127.0.0.1&quot;,
                    &quot;port&quot; : 8080
                }
            ]
        }
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
       Each MySQL Fabric host is described using a JSON object with the following
       members.
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>
            <em>host</em>
          </td>
          <td>
           <p class="para">
            Host name of the MySQL Fabric host.
           </p>
          </td>
          <td>Since 1.6.0.</td>
         </tr>

         <tr>
          <td>
            <em>port</em>
          </td>
          <td>
           <p class="para">
            The TCP/IP port on which the MySQL Fabric host listens
            for remote procedure calls sent by clients such as
            the plugin.
           </p>
          </td>
          <td>Since 1.6.0.</td>
         </tr>

        </tbody>
       
      </table>

      <p class="para">
       The plugin is using PHP streams to communicate with MySQL Fabric
       through XML RPC over HTTP. By default no timeouts are set
       for the network communication. Thus, the plugin defaults to PHP
       stream default timeouts. Those defaults are out of control of
       the plugin itself.
      </p>
      <p class="para">
        An optional timeout value can be set to overrule the PHP streams
        default timeout setting. Setting the timeout in the plugins
        configuration file has the same effect as
        setting a timeout for a PHP user space HTTP connection established
        through PHP streams.
      </p>
      <p class="para">
       The plugins Fabric timeout value unit is seconds. The allowed value
       range is from 0 to 65535. The setting exists since version 1.6.
      </p>
      <p class="para">
       <div class="example" id="example-2288">
        <p><strong>Example #12 Optional timeout for communication with Fabric</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;fabric&quot;: {
            &quot;hosts&quot;: [
                {
                    &quot;host&quot; : &quot;127.0.0.1&quot;,
                    &quot;port&quot; : 8080
                }
            ],
            &quot;timeout&quot;: 2
        }
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
       <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config-v2.trx-stickiness" class="link">Transaction stickiness</a>
       and MySQL Fabric logic can collide. The stickiness option disables switching
       between servers for the duration of a transaction. When using Fabric and
       sharding the user may (erroneously) start a local transaction on one share and
       then attempt to switch to a different shard using either
       <span class="function"><a href="function.mysqlnd-ms-fabric-select-shard.html" class="function">mysqlnd_ms_fabric_select_shard()</a></span> or
       <span class="function"><a href="function.mysqlnd-ms-fabric-select-global.html" class="function">mysqlnd_ms_fabric_select_global()</a></span>. In this case, the
       plugin will not reject the request to switch servers in the middle of a transaction
       but allow the user to switch to another server regardless of the transaction
       stickiness setting used. It is clearly a user error to write such code.
      </p>
      <p class="para">
       If transaction stickiness is enabled and you would like to get an error of type
       warning when calling <span class="function"><a href="function.mysqlnd-ms-fabric-select-shard.html" class="function">mysqlnd_ms_fabric_select_shard()</a></span> or
       <span class="function"><a href="function.mysqlnd-ms-fabric-select-global.html" class="function">mysqlnd_ms_fabric_select_global()</a></span>,
       set the boolean flag <em>trx_warn_server_list_changes</em>.
      </p>
      <p class="para">
       <div class="example" id="example-2289">
        <p><strong>Example #13 Warnings about the violation of transaction boundaries</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;fabric&quot;: {
            &quot;hosts&quot;: [
                {
                    &quot;host&quot; : &quot;127.0.0.1&quot;,
                    &quot;port&quot; : 8080
                }
            ],
            &quot;trx_warn_serverlist_changes&quot;: 1
        },
        &quot;trx_stickiness&quot;: &quot;on&quot;
    }
}</pre>
</div>
        </div>

        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*<br />&nbsp;&nbsp;For&nbsp;the&nbsp;demo&nbsp;the&nbsp;call&nbsp;may&nbsp;fail.<br />&nbsp;&nbsp;Failed&nbsp;or&nbsp;not&nbsp;we&nbsp;get&nbsp;into&nbsp;the&nbsp;state<br />&nbsp;&nbsp;needed&nbsp;for&nbsp;the&nbsp;example.<br />*/<br /></span><span style="color: #007700">@</span><span style="color: #0000BB">mysqlnd_ms_fabric_select_global</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$link</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">begin_transaction</span><span style="color: #007700">();<br />@</span><span style="color: #0000BB">$link</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;IF&nbsp;EXISTS&nbsp;test"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*<br />&nbsp;&nbsp;Switching&nbsp;servers/shards&nbsp;is&nbsp;a&nbsp;mistake&nbsp;due&nbsp;to&nbsp;open<br />&nbsp;&nbsp;local&nbsp;transaction!<br />*/<br /></span><span style="color: #0000BB">mysqlnd_ms_select_global</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
         </div>

         <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen">
<div class="cdata"><pre>
PHP Warning: mysqlnd_ms_fabric_select_global(): (mysqlnd_ms) Fabric server exchange in the middle of a transaction in %s on line %d
</pre></div>
        </div>
       </div>
      </p>
      <p class="para">
       Please, consider the feature experimental. Changes to syntax and semantics may  happen.
      </p>
     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.filters">
      <code class="parameter">filters</code>
      <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
       List of filters. A filter is responsible to filter the list of available
       servers for executing a given statement. Filters can be chained.
       The <em>random</em> and <em>roundrobin</em> filter
       replace the
       <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config.pick" class="link"><em>pick[]</em></a>
       directive used in prior version to select a load balancing policy.
       The <em>user</em> filter replaces the
       <span class="function"><a href="function.mysqlnd-ms-set-user-pick-server.html" class="function">mysqlnd_ms_set_user_pick_server()</a></span> function.
      </p>
      <p class="para">
       Filters may accept parameters to refine their actions.
      </p>
      <p class="para">
       If no load balancing policy is set, the plugin will default to
       <em>random_once</em>. The <em>random_once</em>
       policy picks a random slave server when running the first read-only
       statement. The slave server will be used for all read-only
       statements until the PHP script execution ends. No load balancing
       policy is set and thus, defaulting takes place,
       if neither the <em>random</em> nor the
       <em>roundrobin</em> are part of a configuration section.
      </p>
      <p class="para">
       If a filter chain is configured so that a filter which output no
       more than once server is used as input for a filter which should be given
       more than one server as input, the plugin may emit a warning upon
       opening a connection. The warning may read: <em>(mysqlnd_ms) Error while creating
       filter &#039;%s&#039; . Non-multi filter &#039;%s&#039; already created.
       Stopping in %s on line %d</em>. Furthermore, an error of
       the error code <em>2000</em>, the sql state <em>HY000</em>
       and an error message similar to the warning may be set on the connection
       handle.
      </p>
      <p class="para">
       <div class="example" id="example-2290">
        <p><strong>Example #14 Invalid filter sequence</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;filters&quot;: [
            &quot;roundrobin&quot;,
            &quot;random&quot;
        ]
    }
}</pre>
</div>
         </div>

         <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqli_connect_errno</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">mysqli_connect_error</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$link</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;1&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
         </div>

         <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen">
<div class="cdata"><pre>
PHP Warning:  mysqli::mysqli(): (HY000/2000): (mysqlnd_ms) Error while creating filter &#039;random&#039; . Non-multi filter &#039;roundrobin&#039; already created. Stopping in filter_warning.php on line 1
[2000] (mysqlnd_ms) Error while creating filter &#039;random&#039; . Non-multi filter &#039;roundrobin&#039; already created. Stopping
PHP Warning:  mysqli::query(): Couldn&#039;t fetch mysqli in filter_warning.php on line 3
</pre></div>
        </div>
       </div>
      </p>
    </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.filter-random">
      Filter: <code class="parameter">random</code>
      <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
        The <em>random</em> filter features the random and random once
        load balancing policies, set through the
        <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config.pick" class="link"><em>pick[]</em></a>
        directive in older versions.
      </p>
      <p class="para">
        The random policy will pick a random server whenever
        a read-only statement is to be executed. The random once strategy
        picks a random slave server once and continues using the slave for the
        rest of the PHP web request. Random once is a default,
        if load balancing is not configured through a filter.
      </p>
      <p class="para">
       If the <em>random</em> filter is not given any arguments, it
       stands for random load balancing policy.
      </p>
      <p class="para">
       <div class="example" id="example-2291">
        <p><strong>Example #15 Random load balancing with <em>random</em> filter</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            },
            &quot;slave_1&quot;: {
                &quot;host&quot;: &quot;192.168.78.137&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;filters&quot;: [
            &quot;random&quot;
        ]
    }
}</pre>
</div>
         </div>

       </div>
      </p>
      <p class="para">
       Optionally, the <em>sticky</em> argument can be passed to the
       filter. If the parameter <em>sticky</em> is set to the string
       <em>1</em>, the filter follows the random once
       load balancing strategy.
      </p>
      <p class="para">
       <div class="example" id="example-2292">
        <p><strong>Example #16 Random once load balancing with <em>random</em> filter</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;filters&quot;: {
        &quot;random&quot;: {
            &quot;sticky&quot;: &quot;1&quot;
        }
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
       Both the <em>random</em> and <em>roundrobin</em>
       filters support setting a priority, a weight for a server, since
       PECL/mysqlnd_ms 1.4.0. If the <em>weight</em> argument is
       passed to the filter, it must assign a weight for all servers. Servers
       must be given an alias name in the <em>slave</em> respectively
       <em>master</em> server lists. The alias must be used
       to reference servers for assigning a priority with <em>weight</em>.
      </p>
      <p class="para">
       <div class="example" id="example-2293">
        <p><strong>Example #17 Referencing error</strong></p>
        <div class="example-contents screen">
<div class="cdata"><pre>
[E_RECOVERABLE_ERROR] mysqli_real_connect(): (mysqlnd_ms) Unknown server &#039;slave3&#039; in &#039;random&#039; filter configuration. Stopping in %s on line %d
</pre></div>
        </div>
       </div>
      </p>
      <p class="para">
       Using a wrong alias name with <em>weight</em> may result in
       an error similar to the shown above.
      </p>
      <p class="para">
       If <em>weight</em> is omitted, the default weight of
       all servers is one.
      </p>
      <p class="para">
       <div class="example" id="example-2294">
        <p><strong>Example #18 Assigning a <em>weight</em> for load balancing</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
   &quot;myapp&quot;: {
       &quot;master&quot;: {
           &quot;master1&quot;:{
               &quot;host&quot;:&quot;localhost&quot;,
               &quot;socket&quot;:&quot;\/var\/run\/mysql\/mysql.sock&quot;
           }
       },
       &quot;slave&quot;: {
           &quot;slave1&quot;: {
               &quot;host&quot;:&quot;192.168.2.28&quot;,
               &quot;port&quot;:3306
           },
           &quot;slave2&quot;: {
               &quot;host&quot;:&quot;192.168.2.29&quot;,
               &quot;port&quot;:3306
           },
           &quot;slave3&quot;: {
               &quot;host&quot;:&quot;192.0.43.10&quot;,
               &quot;port&quot;:3306
           },
       },
       &quot;filters&quot;: {
           &quot;random&quot;: {
               &quot;weights&quot;: {
                   &quot;slave1&quot;:8,
                   &quot;slave2&quot;:4,
                   &quot;slave3&quot;:1,
                   &quot;master1&quot;:1
               }
           }
       }
   }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
       At the average a server assigned a weight of two will be selected twice
       as often as a server assigned a weight of one. Different weights can be
       assigned to reflect differently sized machines, to prefer co-located slaves
       which have a low network latency or, to configure a standby failover server.
       In the latter case, you may want to assign the standby server a very low
       weight in relation to the other servers. For example, given the
       configuration above <em>slave3</em> will get only some eight
       percent of the requests in the average. As long as <em>slave1</em>
       and <em>slave2</em> are running, it will be used sparsely,
       similar to a standby failover server. Upon failure of <em>slave1</em>
       and <em>slave2</em>, the usage of <em>slave3</em>
       increases. Please, check the notes on failover before using
       <em>weight</em> this way.
      </p>
      <p class="para">
       Valid weight values range from 1 to 65535.
      </p>
      <p class="para">
       Unknown arguments are ignored by the filter. No warning or error is given.
      </p>
      <p class="para">
        The filter expects one or more servers as input. Outputs one server.
        A filter sequence such as
        <em>random</em>, <em>roundrobin</em> may
        cause a warning and an error message to be set on the connection
        handle when executing a statement.
      </p>
      <p class="para">
       List of filter arguments.
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>
            <em>sticky</em>
          </td>
          <td>
           <p class="para">
            Enables or disabled random once load
            balancing policy. See above.
           </p>
          </td>
          <td>Since 1.2.0.</td>
         </tr>

         <tr>
          <td>
            <em>weight</em>
          </td>
          <td>
           <p class="para">
            Assigns a load balancing weight/priority to
            a server. Please, see above for a description.
           </p>
          </td>
          <td>Since 1.4.0.</td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.filter-roundrobin">
      Filter: <code class="parameter">roundrobin</code>
      <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
       If using the <em>roundrobin</em> filter, the plugin
       iterates over the list of  configured slave servers to pick a server
       for statement execution. If the plugin reaches the end of the list,
       it wraps around to the beginning of the list and picks the first
       configured slave server.
      </p>
      <p class="para">
       <div class="example" id="example-2295">
        <p><strong>Example #19 <em>roundrobin</em> filter</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;filters&quot;: [
            &quot;roundrobin&quot;
        ]
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
        Expects one or more servers as input. Outputs one server.
        A filter sequence such as
        <em>roundrobin</em>, <em>random</em> may
        cause a warning and an error message to be set on the connection
        handle when executing a statement.
      </p>
      <p class="para">
       List of filter arguments.
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>
            <em>weight</em>
          </td>
          <td>
           <p class="para">
            Assigns a load balancing weight/priority to
            a server. Please, find a description
            <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config-v2.filter-random" class="link">above</a>.
           </p>
          </td>
          <td>Since 1.4.0.</td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.filter-user">
      Filter: <code class="parameter">user</code>
      <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
        The <em>user</em> replaces
       <span class="function"><a href="function.mysqlnd-ms-set-user-pick-server.html" class="function">mysqlnd_ms_set_user_pick_server()</a></span> function,
       which was removed in 1.1.0-beta. The filter sets a callback for user-defined
       read/write splitting and server selection.
      </p>
      <p class="para">
        The plugins built-in read/write query split mechanism decisions can be
        overwritten in two ways. The easiest way is to prepend a query string
        with the SQL hints <strong><code>MYSQLND_MS_MASTER_SWITCH</code></strong>,
        <strong><code>MYSQLND_MS_SLAVE_SWITCH</code></strong> or
        <strong><code>MYSQLND_MS_LAST_USED_SWITCH</code></strong>. Using SQL hints one can
        control, for example, whether a query shall be send to the MySQL replication
        master server or one of the slave servers. By help of SQL hints it is
        not possible to pick a certain slave server for query execution.
      </p>
      <p class="para">
       Full control on server selection can be gained using a callback function.
       Use of a callback is recommended to expert users only because the callback
       has to cover all cases otherwise handled by the plugin.
      </p>
      <p class="para">
       The plugin will invoke the callback function for selecting a server from the
       lists of configured master and slave servers. The callback function
       inspects the query to run and picks a server for query execution by returning
       the hosts URI, as found in the master and slave list.
      </p>
      <p class="para">
       If the lazy connections are enabled and the callback chooses a slave server for
       which no connection has been established so far and establishing the connection
       to the slave fails, the plugin will return an error upon the next action
       on the failed connection, for example, when running a query. It is the
       responsibility of the application developer to handle the error. For example,
       the application can re-run the query to trigger a new server selection and
       callback invocation. If so, the callback must make sure to select
       a different slave, or check slave availability, before returning to
       the plugin to prevent an endless loop.
      </p>
      <p class="para">
       <div class="example" id="example-2296">
        <p><strong>Example #20 Setting a callback</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;filters&quot;: {
            &quot;user&quot;: {
                &quot;callback&quot;: &quot;pick_server&quot;
            }
        }
    }
}</pre>
</div>
         </div>

       </div>
      </p>
      <p class="para">
       The callback is supposed to return a host to run the query on.
       The host URI is to be taken from the master and slave connection lists
       passed to the callback function. If callback returns a value neither
       found in the master nor in the slave connection lists the plugin
       will emit an error of the type <em>E_RECOVERABLE_ERROR</em>
       The error may read like
       <em>  (mysqlnd_ms) User filter callback has returned an unknown server.
       The server &#039;server that is not in master or slave list&#039; can neither be found
       in the master list nor in the slave list</em>.
       If the application catches the error to ignore it, follow up errors
       may be set on the connection handle, for example,
       <em>(mysqlnd_ms) No connection selected by the last filter</em> with
       the error code <em>2000</em> and the sqlstate <em>HY000</em>.
       Furthermore a warning may be emitted.
      </p>
      <p class="para">
       Referencing a non-existing function as a callback will result
       in any error of the type <em>E_RECOVERABLE_ERROR</em> whenever
       the plugin tries to callback function. The error message may reads like:
       <em>(mysqlnd_ms) Specified callback (pick_server) is
       not a valid callback</em>. If the application catches the error to
       ignore it, follow up errors may be set on the connection handle, for example,
       <em>(mysqlnd_ms) Specified callback (pick_server) is
       not a valid callback</em> with the error code <em>2000</em>
       and the sqlstate <em>HY000</em>. Furthermore a warning
       may be emitted.
      </p>
      <p class="para">
       The following parameters are passed from the plugin to the callback.
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Parameter</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
           <td>
             <em>connected_host</em>
           </td>
           <td>
            <p class="para">
             URI of the currently connected database server.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>query</em>
           </td>
           <td>
            <p class="para">
             Query string of the statement for which a server needs
             to be picked.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>masters</em>
           </td>
           <td>
            <p class="para">
             List of master servers to choose from. Note, that the list of master
             servers may not be identical to the list of configured master
             servers if the filter is not the first in the filter chain.
             Previously run filters may have reduced the master
             list already.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>slaves</em>
           </td>
           <td>
            <p class="para">
             List of slave servers to choose from. Note, that the list of slave
             servers may not be identical to the list of configured slave
             servers if the filter is not the first in the filter chain.
             Previously run filters may have reduced the slave
             list already.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>last_used_connection</em>
           </td>
           <td>
            <p class="para">
              URI of the server of the connection used to execute the previous
              statement on.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>in_transaction</em>
           </td>
           <td>
            <p class="para">
             Boolean flag indicating whether the statement is
             part of an open transaction. If autocommit mode is turned
             off, this will be set to <strong><code>TRUE</code></strong>. Otherwise
             it is set to <strong><code>FALSE</code></strong>.
            </p>
            <p class="para">
             Transaction detection is based on monitoring the
             mysqlnd library call <em>set_autocommit</em>.
             Monitoring is not possible before PHP 5.4.0. Please, see
             <a href="mysqlnd-ms.pooling.html" class="link">connection pooling and switching</a>
             concepts discussion for further details.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

        </tbody>
       
      </table>

      <p class="para">
       <div class="example" id="example-2297">
        <p><strong>Example #21 Using a callback</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.2.27&quot;,
                &quot;port&quot;: &quot;3306&quot;
            },
            &quot;slave_1&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;filters&quot;: {
            &quot;user&quot;: {
                &quot;callback&quot;: &quot;pick_server&quot;
            }
        }
    }
}</pre>
</div>
         </div>

         <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">pick_server</span><span style="color: #007700">(</span><span style="color: #0000BB">$connected</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$masters</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$slaves</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$last_used_connection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$in_transaction</span><span style="color: #007700">)<br />{<br />&nbsp;static&nbsp;</span><span style="color: #0000BB">$slave_idx&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;static&nbsp;</span><span style="color: #0000BB">$num_slaves&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br />&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_null</span><span style="color: #007700">(</span><span style="color: #0000BB">$num_slaves</span><span style="color: #007700">))<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$num_slaves&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$slaves</span><span style="color: #007700">);<br /><br />&nbsp;</span><span style="color: #FF8000">/*&nbsp;default:&nbsp;fallback&nbsp;to&nbsp;the&nbsp;plugins&nbsp;build-in&nbsp;logic&nbsp;*/<br />&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br /><br />&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"User&nbsp;has&nbsp;connected&nbsp;to&nbsp;'%s'...\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$connected</span><span style="color: #007700">);<br />&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"...&nbsp;deciding&nbsp;where&nbsp;to&nbsp;run&nbsp;'%s'\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br />&nbsp;</span><span style="color: #0000BB">$where&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqlnd_ms_query_is_select</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br />&nbsp;switch&nbsp;(</span><span style="color: #0000BB">$where</span><span style="color: #007700">)<br />&nbsp;{<br />&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">MYSQLND_MS_QUERY_USE_MASTER</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"...&nbsp;using&nbsp;master\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$masters</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">MYSQLND_MS_QUERY_USE_SLAVE</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;SELECT&nbsp;or&nbsp;SQL&nbsp;hint&nbsp;for&nbsp;using&nbsp;slave&nbsp;*/<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"FROM&nbsp;table_on_slave_a_only"</span><span style="color: #007700">))<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;a&nbsp;table&nbsp;which&nbsp;is&nbsp;only&nbsp;on&nbsp;the&nbsp;first&nbsp;configured&nbsp;slave&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"...&nbsp;access&nbsp;to&nbsp;table&nbsp;available&nbsp;only&nbsp;on&nbsp;slave&nbsp;A&nbsp;detected\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$slaves</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;round&nbsp;robin&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"...&nbsp;some&nbsp;read-only&nbsp;query&nbsp;for&nbsp;a&nbsp;slave\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$slaves</span><span style="color: #007700">[</span><span style="color: #0000BB">$slave_idx</span><span style="color: #007700">++&nbsp;%&nbsp;</span><span style="color: #0000BB">$num_slaves</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">MYSQLND_MS_QUERY_LAST_USED</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"...&nbsp;using&nbsp;last&nbsp;used&nbsp;server\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$last_used_connection</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;break;<br />&nbsp;}<br /><br />&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"...&nbsp;ret&nbsp;=&nbsp;'%s'\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ret</span><span style="color: #007700">);<br />&nbsp;return&nbsp;</span><span style="color: #0000BB">$ret</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /><br />if&nbsp;(!(</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;1&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">)))<br />&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">);<br />else<br />&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /><br />if&nbsp;(!(</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;2&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">)))<br />&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">);<br />else<br />&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /><br /><br />if&nbsp;(!(</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;table_on_slave_a_only"</span><span style="color: #007700">)))<br />&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">);<br />else<br />&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
         </div>

         <div class="example-contents"><p>The above example will output:</p></div>
         <div class="example-contents screen">
<div class="cdata"><pre>
User has connected to &#039;myapp&#039;...
... deciding where to run &#039;SELECT 1 FROM DUAL&#039;
... some read-only query for a slave
... ret = &#039;tcp://192.168.2.27:3306&#039;
User has connected to &#039;myapp&#039;...
... deciding where to run &#039;SELECT 2 FROM DUAL&#039;
... some read-only query for a slave
... ret = &#039;tcp://192.168.78.136:3306&#039;
User has connected to &#039;myapp&#039;...
... deciding where to run &#039;SELECT * FROM table_on_slave_a_only&#039;
... access to table available only on slave A detected
... ret = &#039;tcp://192.168.2.27:3306&#039;
</pre></div>
         </div>
       </div>
      </p>
     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.filter-user-multi">
      Filter: <code class="parameter">user_multi</code>
      <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
       The <em>user_multi</em> differs from the <em>user</em>
       only in one aspect. Otherwise, their syntax is identical.
       The <em>user</em> filter must pick
       and return exactly one node for statement execution. A filter chain
       usually ends with a filter that emits only one node. The filter chain
       shall reduce the list of candidates for statement execution down to
       one. This, only one node left, is the case after the <em>user</em>
       filter has been run.
      </p>
      <p class="para">
       The <em>user_multi</em> filter is a multi filter. It returns a
       list of slave and a list of master servers. This list needs further filtering
       to identify exactly one node for statement execution. A multi filter is typically
       placed at the top of the filter chain. The <em>quality_of_service</em>
       filter is another example of a multi filter.
      </p>
      <p class="para">
       The return value of the callback set for <em>user_multi</em> must
       be an array with two elements. The first element holds a list of selected master
       servers. The second element contains a list of selected slave servers. The
       lists shall contain the keys of the slave and master servers as found in
       the slave and master lists passed to the callback. The below example returns
       random master and slave lists extracted from the functions input.
      </p>
      <p class="para">
      <div class="example" id="example-2298">
        <p><strong>Example #22 Returning random masters and slaves</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">pick_server</span><span style="color: #007700">(</span><span style="color: #0000BB">$connected</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$masters</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$slaves</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$last_used_connection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$in_transaction</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$picked_masters&nbsp;</span><span style="color: #007700">=&nbsp;array()<br />&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$masters&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">mt_rand</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$picked_masters</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$picked_slaves&nbsp;</span><span style="color: #007700">=&nbsp;array()<br />&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$slaves&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">mt_rand</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$picked_slaves</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;return&nbsp;array(</span><span style="color: #0000BB">$picked_masters</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$picked_slaves</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
         </div>

       </div>
      </p>
      <p class="para">
       The plugin will issue an
       error of type <em>E_RECOVERABLE</em> if the callback fails to return
       a server list. The error may read <em>(mysqlnd_ms) User multi
       filter callback has not returned a list of servers to use.
       The callback must return an array in %s on line %d</em>. In case the
       server list is not empty but has invalid servers key/ids in it, an error
       of type <em>E_RECOVERABLE</em> will the thrown with an
       error message like <em>(mysqlnd_ms) User multi filter callback
       has returned an invalid list of servers to use.
       Server id is negative in %s on line %d</em>, or similar.
      </p>
      <p class="para">
       Whether an error is emitted in case of an empty slave or master list
       depends on the configuration. If an empty master list is returned
       for a write operation, it is likely that the plugin will emit a
       warning that may read <em>(mysqlnd_ms) Couldn&#039;t find the appropriate
       master connection. 0 masters to choose from. Something is wrong in %s on line %d</em>.
       Typically a follow up error of type <em>E_ERROR</em> will happen.
       In case of a read operation and an empty slave list the behavior depends
       on the fail over configuration. If fail over to master is enabled, no
       error should appear. If fail over to master is deactivated the plugin will
       emit a warning that may read <em>(mysqlnd_ms) Couldn&#039;t find the appropriate
       slave connection. 0 slaves to choose from. Something is wrong in %s on line %d</em>.
      </p>
     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.filter-node-groups">
      Filter: <code class="parameter">node_groups</code>
      <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
       The <em>node_groups</em> filter lets you group cluster nodes
       and query selected groups, for example, to support data partitioning.
       Data partitioning can be required for manual sharding, primary copy based
       clusters running multiple masters, or to avoid hot spots in update everywhere
       clusters that have no built-in partitioning. The filter is a multi filter
       which returns zero, one or multiple of its input servers. Thus, it
       must be followed by other filters to reduce the number of candidates
       down to one for statement execution.
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>
           <em>user defined node group name</em>
          </td>
          <td>
            <p class="para">
             One or more node groups must be defined. A node group can have an
             arbitrary user defined name. The name is used in combination with
             a SQL hint to restrict query execution to the nodes listed for the
             node group. To run a query on any of the servers of a node group,
             the query must begin with the SQL hint
             <em>/*user defined node group name*/</em>.
             Please note, no white space is allowed around
             <em>user defined node group name</em>. Because
             <em>user defined node group name</em> is used as-is
             as part of a SQL hint, you should choose the name that is compliant
             with the SQL language.
            </p>
            <p class="para">
             Each node group entry must contain a list of <em>master</em>
             servers. Additional <em>slave</em> servers are allowed.
             Failing to provide a list of <em>master</em> for a node group
             <em>name_of_group</em> may cause an
             error of type <strong><code>E_RECOVERABLE_ERROR</code></strong> like
             <em>(mysqlnd_ms) No masters configured in node group &#039;name_of_group&#039; for &#039;node_groups&#039; filter</em>.
            </p>
            <p class="para">
             The list of master and slave servers must reference corresponding
             entries in the
             <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config-v2.master" class="link">global master</a>
             respectively <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config-v2.slave" class="link">slave</a>
             server list. Referencing an unknown server in either of the both server
             lists may cause an <strong><code>E_RECOVERABLE_ERROR</code></strong> error like
             <em>(mysqlnd_ms) Unknown master &#039;server_alias_name&#039; (section &#039;name_of_group&#039;) in &#039;node_groups&#039; filter configuration</em>.
            </p>
            <p class="para">
             <div class="example" id="example-2299">
               <p><strong>Example #23 Manual partitioning</strong></p>
                <div class="example-contents">
<div class="inicode"><pre class="inicode">{
  &quot;myapp&quot;: {
       &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;,
                &quot;socket&quot;: &quot;\/tmp\/mysql.sock&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.2.28&quot;,
                &quot;port&quot;: 3306
            },
            &quot;slave_1&quot;: {
                &quot;host&quot;: &quot;127.0.0.1&quot;,
                &quot;port&quot;: 3311
            }
        },
        &quot;filters&quot;: {
            &quot;node_groups&quot;: {
                &quot;Partition_A&quot; : {
                    &quot;master&quot;: [&quot;master_0&quot;],
                    &quot;slave&quot;: [&quot;slave_0&quot;]
                }
            },
           &quot;roundrobin&quot;: []
        }
    }
}</pre>
</div>
              </div>

             </div>
            </p>
            <p class="para">
              Please note, if a filter chain
              generates an empty slave list and the PHP configuration directive
              <em>mysqlnd_ms.multi_master=0</em> is used, the plugin may
              emit a warning.
            </p>
          </td>
          <td>Since 1.5.0.</td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.filter-qos">
      Filter: <code class="parameter">quality_of_service</code>
      <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
       The <em>quality_of_service</em> identifies cluster nodes
       capable of delivering a certain quality of service. It is a multi filter
       which returns zero, one or multiple of its input servers. Thus, it
       must be followed by other filters to reduce the number of candidates
       down to one for statement execution.
      </p>
      <p class="para">
       The <em>quality_of_service</em> filter has been introduced in 1.2.0-alpha.
       In the 1.2 series the filters focus is on the consistency aspect of
       service quality. Different types of clusters offer different
       default data consistencies. For example, an asynchronous MySQL
       replication slave offers eventual consistency. The slave may not
       be able to deliver requested data because it has not replicated the write,
       it may serve stale database because its lagging behind or it may serve
       current information. Often, this is acceptable. In some cases
       higher consistency levels are needed for the application to work correct.
       In those cases, the <em>quality_of_service</em> can filter out cluster nodes
       which cannot deliver the necessary quality of service.
      </p>
      <p class="para">
       The <em>quality_of_service</em> filter can be replaced or created
       at runtime. A successful call to
       <span class="function"><a href="function.mysqlnd-ms-set-qos.html" class="function">mysqlnd_ms_set_qos()</a></span>
       removes all existing <em>qos</em> filter entries from the
       filter list and installs a new one at the very beginning. All settings
       that can be made through
       <span class="function"><a href="function.mysqlnd-ms-set-qos.html" class="function">mysqlnd_ms_set_qos()</a></span>
       can also be in the plugins configuration file. However, use of the function
       is by far the most common use case. Instead of setting session consistency and
       strong consistency service levels in the plugins configuration file it is
       recommended to define only masters and no slaves. Both service levels will
       force the use of masters only. Using an empty slave list shortens the
       configuration file, thus improving readability. The only service level for which
       there is a case of defining in the plugins configuration file is the combination
       of eventual consistency and maximum slave lag.
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
           <td>
             <em>eventual_consistency</em>
           </td>
           <td>
            <p class="para">
             Request eventual consistency. Allows the use of all
             master and slave servers. Data returned may or may not be current.
            </p>
            <p class="para">
             Eventual consistency accepts an optional <em>age</em>
             parameter. If <em>age</em> is given the plugin considers
             only slaves for reading for which MySQL replication reports
             a slave lag less or equal to <em>age</em>.
             The replication lag is measure using <em>SHOW SLAVE STATUS</em>.
             If the plugin fails to fetch the replication lag, the slave tested
             is skipped. Implementation details and tips are given in the
             <a href="mysqlnd-ms.qos-consistency.html" class="link">quality of service concepts section</a>.
            </p>
            <p class="para">
              Please note, if a filter chain
              generates an empty slave list and the PHP configuration directive
              <em>mysqlnd_ms.multi_master=0</em> is used, the plugin may
              emit a warning.
            </p>
            <p class="para">
             <div class="example" id="example-2300">
               <p><strong>Example #24 Global limit on slave lag</strong></p>
                <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.2.27&quot;,
                &quot;port&quot;: &quot;3306&quot;
            },
            &quot;slave_1&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;filters&quot;: {
            &quot;quality_of_service&quot;: {
                &quot;eventual_consistency&quot;: {
                    &quot;age&quot;:123
                }
            }
        }
    }
}</pre>
</div>
              </div>

             </div>
            </p>
          </td>
          <td>Since 1.2.0.</td>
         </tr>

         <tr>
           <td>
             <em>session_consistency</em>
           </td>
           <td>
            <p class="para">
              Request session consistency (read your writes). Allows use of all masters
              and all slaves which are in sync with the master.
              If no further parameters are given slaves are filtered out
              as there is no reliable way to test if a slave has caught up
              to the master or is lagging behind. Please note, if a filter chain
              generates an empty slave list and the PHP configuration directive
              <em>mysqlnd_ms.multi_master=0</em> is used, the plugin may
              emit a warning.
            </p>
            <p class="para">
             Session consistency temporarily requested using
             <span class="function"><a href="function.mysqlnd-ms-set-qos.html" class="function">mysqlnd_ms_set_qos()</a></span> is a valuable alternative
             to using <em>master_on_write</em>.
             <em>master_on_write</em> is likely to send more statements
             to the master than needed. The application may be able to continue
             operation at a lower consistency level after it has done
             some critical reads.
            </p>
          </td>
          <td>Since 1.1.0.</td>
         </tr>

         <tr>
           <td>
             <em>strong_consistency</em>
           </td>
           <td>
            <p class="para">
              Request strong consistency. Only masters will be used.
            </p>
          </td>
          <td>Since 1.2.0.</td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.failover">
      <code class="parameter">failover</code>
      Up to and including 1.3.x: <span class="type"><a href="language.types.string.html" class="type string">string</a></span>.
      Since 1.4.0: <span class="type"><a href="language.types.object.html" class="type object">object</a></span>.
     </dt>

     <dd>

      <p class="para">
       Failover policy. Supported policies:
       <em>disabled</em> (default), <em>master</em>,
       <em>loop_before_master</em> (Since 1.4.0).
      </p>
      <p class="para">
       If no failover policy is set, the plugin will not do any
       automatic failover (<em>failover=disabled</em>). Whenever
       the plugin fails to connect a server it will emit a warning and
       set the connections error code and message. Thereafter it is up to
       the application to handle the error and, for example, resent the
       last statement to trigger the selection of another server.
      </p>
      <p class="para">
       Please note, the automatic failover logic is applied when opening
       connections only. Once a connection has been opened no automatic attempts
       are made to reopen it in case of an error. If, for example, the server
       a connection is connected to is shut down and the  user attempts to
       run a statement on the connection, no automatic failover
       will be tried. Instead, an error will be reported.
      </p>
      <p class="para">
       If using <em>failover=master</em> the plugin will implicitly
       failover to a master, if available. Please check the
       concepts documentation to learn about potential
       pitfalls and risks of using <em>failover=master</em>.
      </p>
      <p class="para">
       <div class="example" id="example-2301">
        <p><strong>Example #25 Optional master failover when failing to connect to slave (PECL/mysqlnd_ms &lt; 1.4.0)</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;failover&quot;: &quot;master&quot;
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
       Since PECL/mysqlnd_ms 1.4.0 the failover configuration keyword refers to an
       object.
      </p>
      <p class="para">
       <div class="example" id="example-2302">
        <p><strong>Example #26 New syntax since 1.4.0</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;failover&quot;: {&quot;strategy&quot;: &quot;master&quot; }
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>
           <em>strategy</em>
          </td>
          <td>
           <p class="para">
            Failover policy. Possible values:
            <em>disabled</em> (default), <em>master</em>,
            <em>loop_before_master</em>
           </p>
           <p class="para">
            A value of <em>disabled</em> disables automatic failover.
           </p>
           <p class="para">
            Setting <em>master</em> instructs the plugin to try
            to connect to a master in case of a slave connection error. If the
            master connection attempt fails, the plugin exists the failover
            loop and returns an error to the user.
           </p>
           <p class="para">
             If using <em>loop_before_master</em> and a slave request
             is made, the plugin tries to connect to other slaves before failing
             over to a master. If multiple master are given and multi master is enabled,
             the plugin also loops over the list of masters and attempts to connect
             before returning an error to the user.
           </p>
          </td>
          <td>Since 1.4.0.</td>
         </tr>

         <tr>
          <td>
           <em>remember_failed</em>
          </td>
          <td>
           <p class="para">
            Remember failures for the duration of a web request. Default:
             <em>false</em>.
            </p>
            <p class="para">
             If set to <em>true</em> the plugin will remember failed
             hosts and skip the hosts in all future load balancing made for
             the duration of the current web request.
            </p>
          </td>
          <td>
           Since 1.4.0. The feature is only available together
           with the <em>random</em> and <em>roundrobin</em>
           load balancing filter. Use of the setting is recommended.
          </td>
         </tr>

         <tr>
           <td>
            <em>max_retries</em>
           </td>
           <td>
            <p class="para">
             Maximum number of connection attempts before skipping host.
             Default: <em>0</em> (no limit).
            </p>
            <p class="para">
             The setting is used to prevent hosts from being dropped of the
             host list upon the first failure. If set to <em>n &gt; 0</em>,
             the plugin will keep the node in the node list even after a failed
             connection attempt. The node will not be removed immediately from the slave respectively
             master lists after the first connection failure but instead be tried to
             connect to up to <em>n</em> times in future load balancing rounds
             before being removed.
            </p>
          </td>
          <td>
           Since 1.4.0. The feature is only available together
           with the <em>random</em> and <em>roundrobin</em>
           load balancing filter.
          </td>
         </tr>

        </tbody>
       
      </table>

      <p class="para">
       Setting <em>failover</em> to any other value but
       <em>disabled</em>, <em>master</em> or
       <em>loop_before_master</em>
       will not emit any warning or error.
      </p>
     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.lazy-connections">
      <code class="parameter">lazy_connections</code>
      <span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span>
     </dt>

     <dd>

      <p class="para">
       Controls the use of lazy connections. Lazy connections
       are connections which are not opened before the client sends the first
       connection. Lazy connections are a default.
      </p>
      <p class="para">
       It is strongly recommended to use lazy connections.
       Lazy connections help to keep the number of open connections low.
       If you disable lazy connections and, for example, configure one MySQL
       replication master server and two MySQL replication slaves, the
       plugin will open three connections upon the first call to a
       connect function although the application might use the master
       connection only.
      </p>
      <p class="para">
       Lazy connections bare a risk if you make heavy use of actions
       which change the state of a connection. The plugin does not dispatch
       all state changing actions to all connections from the connection pool.
       The few dispatched actions are applied to already opened connections
       only. Lazy connections opened in the future are not affected.
       Only some settings are &quot;remembered&quot; and applied when lazy
       connections are opened.
      </p>
      <p class="para">
       <div class="example" id="example-2303">
        <p><strong>Example #27 Disabling lazy connection</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;lazy_connections&quot;: 0
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
       Please, see also <em>server_charset</em> to overcome potential
       problems with string escaping and servers using different default
       charsets.
      </p>
     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.server-charset">
      <code class="parameter">server_charset</code>
      <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
     </dt>

     <dd>

      <p class="para">
       The setting has been introduced in 1.4.0. It is recommended to set it
       if using lazy connections.
      </p>
      <p class="para">
       The <em>server_charset</em> setting serves two purposes. It
       acts as a fallback charset to be used for string escaping done before
       a connection has been established and it helps to avoid escaping pitfalls
       in heterogeneous environments which servers using different default charsets.
      </p>
      <p class="para">
       String escaping takes a connections charset into account. String escaping
       is not possible before a connection has been opened and the connections
       charset is known. The use of lazy connections delays the actual opening
       of connections until a statement is send.
      </p>
      <p class="para">
       An application using lazy connections may attempt to escape a string
       before sending a statement. In fact, this should be a common case as
       the statement string may contain the string that is to be escaped.
       However, due to the lazy connection feature no connection has been opened
       yet and escaping fails. The plugin may report an error of the type
       <em>E_WARNING</em> and a message like <em>(mysqlnd_ms)
       string escaping doesn&#039;t work without established connection.
       Possible solution is to add server_charset to your configuration</em>
       to inform you of the pitfall.
      </p>
      <p class="para">
       Setting <em>server_charset</em> makes the plugin use
       the given charset for string escaping done on lazy connection handles
       before establishing a network connection to MySQL. Furthermore, the
       plugin will enforce the use of the charset when the connection is
       established.
      </p>
      <p class="para">
       Enforcing the use of the configured charset used for escaping is done
       to prevent tapping into the pitfall of using a different charset for
       escaping than used later for the connection. This has the additional
       benefit of removing the need to align the charset configuration of all
       servers used. No matter what the default charset on any of the servers is,
       the plugin will set the configured one as a default.
      </p>
      <p class="para">
       The plugin does not stop the user from changing the charset at any time
       using the <span class="function"><strong>set_charset()</strong></span> call or corresponding SQL statements.
       Please, note that the use of SQL is not recommended as it cannot be monitored
       by the plugin. The user can, for example, change the charset on a
       lazy connection handle after escaping a string and before the actual connection
       is opened. The charset set by the user will be used for any subsequent escaping
       before the connection is established. The connection will be established
       using the configured charset, no matter what the server charset is or
       what the user has set before. Once a connection has been opened,
       <em>set_charset</em> is of no meaning anymore.
      </p>
      <p class="para">
       <div class="example" id="example-2304">
        <p><strong>Example #28 String escaping on a lazy connection handle</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;lazy_connections&quot;: 1,
        &quot;server_charset&quot; : &quot;utf8&quot;
    }
}</pre>
</div>
        </div>

        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">real_escape</span><span style="color: #007700">(</span><span style="color: #DD0000">"this&nbsp;will&nbsp;be&nbsp;escaped&nbsp;using&nbsp;the&nbsp;server_charset&nbsp;setting&nbsp;-&nbsp;utf8"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set_charset</span><span style="color: #007700">(</span><span style="color: #DD0000">"latin1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">real_escape</span><span style="color: #007700">(</span><span style="color: #DD0000">"this&nbsp;will&nbsp;be&nbsp;escaped&nbsp;using&nbsp;latin1"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;server_charset&nbsp;implicitly&nbsp;set&nbsp;-&nbsp;utf8&nbsp;connection&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;'This&nbsp;connection&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;server_charset&nbsp;upon&nbsp;establishing'&nbsp;AS&nbsp;_msg&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;latin1&nbsp;used&nbsp;from&nbsp;now&nbsp;on&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set_charset</span><span style="color: #007700">(</span><span style="color: #DD0000">"latin1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
         </div>

       </div>
      </p>
     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.master-on-write">
      <code class="parameter">master_on_write</code>
      <span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span>
     </dt>

     <dd>

      <p class="para">
       If set, the plugin will use the master server only after the
       first statement has been executed on the master. Applications
       can still send statements to the slaves using SQL hints to
       overrule the automatic decision.
      </p>
      <p class="para">
       The setting may help with replication lag. If an application runs
       an <em>INSERT</em> the plugin will, by default, use the
       master to execute all following statements, including
       <em>SELECT</em> statements. This helps to avoid problems
       with reads from slaves which have not replicated the
       <em>INSERT</em> yet.
      </p>
      <p class="para">
       <div class="example" id="example-2305">
        <p><strong>Example #29 Master on write for consistent reads</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;master_on_write&quot;: 1
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
       Please, note the <em>quality_of_service</em> filter introduced
       in version 1.2.0-alpha. It gives finer control, for example, for achieving read-your-writes
       and, it offers additional functionality introducing
       <a href="mysqlnd-ms.qos-consistency.html" class="link">service levels</a>.
      </p>
      <p class="para">
       All <a href="mysqlnd-ms.plugin-ini-json.html#ini.mysqlnd-ms-plugin-config-v2.trx-stickiness" class="link">transaction stickiness</a> settings,
       including <em>trx_stickiness=on</em>, are overruled by <em>master_on_write=1</em>.
      </p>
     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.trx-stickiness">
      <code class="parameter">trx_stickiness</code>
      <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
     </dt>

     <dd>

      <p class="para">
       Transaction stickiness policy. Supported policies:
       <em>disabled</em> (default), <em>master</em>.
      </p>
      <p class="para">
       The setting requires 5.4.0 or newer. If used with PHP older than 5.4.0,
       the plugin will emit a warning like
       <em>(mysqlnd_ms) trx_stickiness strategy is not supported before PHP 5.3.99</em>.
      </p>
      <p class="para">
       If no transaction stickiness policy is set or,
       if setting <em>trx_stickiness=disabled</em>,
       the plugin is not transaction aware. Thus, the plugin may load balance
       connections and switch connections in the middle of a transaction.
       The plugin is not transaction safe. SQL hints must be used
       avoid connection switches during a transaction.
      </p>
      <p class="para">
       As of PHP 5.4.0 the mysqlnd library allows the plugin to monitor
       the <em>autocommit</em> mode set by calls to the
       libraries <em>set_autocommit()</em> function.
       If setting <em>set_stickiness=master</em> and
       <em>autocommit</em> gets disabled by a PHP MySQL extension
       invoking the <em>mysqlnd</em> library internal
       function call <em>set_autocommit()</em>, the plugin is made
       aware of the begin of a transaction. Then, the plugin stops load balancing
       and directs all statements to the master server until
       <em>autocommit</em> is enabled. Thus, no SQL hints are required.
      </p>
      <p class="para">
       An example of a PHP MySQL API function calling the <em>mysqlnd</em>
       library internal function call <em>set_autocommit()</em> is
       <span class="function"><a href="mysqli.autocommit.html" class="function">mysqli_autocommit()</a></span>.
      </p>
      <p class="para">
       Although setting <em>trx_stickiness=master</em>, the plugin
       cannot be made aware of <em>autocommit</em> mode changes caused
       by SQL statements such as <em>SET AUTOCOMMIT=0</em> or <em>BEGIN</em>.
      </p>
      <p class="para">
       As of PHP 5.5.0, the mysqlnd library features additional C API calls to
       control transactions. The level of control matches the one offered by SQL
       statements. The <em>mysqli</em> API has been modified to use
       these calls. Since version 1.5.0, PECL/mysqlnd_ms can monitor not only
       <span class="function"><a href="mysqli.autocommit.html" class="function">mysqli_autocommit()</a></span>, but also <span class="function"><strong>mysqli_begin()</strong></span>,
       <span class="function"><a href="mysqli.commit.html" class="function">mysqli_commit()</a></span> and <span class="function"><a href="mysqli.rollback.html" class="function">mysqli_rollback()</a></span> to
       detect transaction boundaries and stop load balancing for the duration of
       a transaction.
      </p>
      <p class="para">
       <div class="example" id="example-2306">
        <p><strong>Example #30 Using master to execute transactions</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
        },
        &quot;trx_stickiness&quot;: &quot;master&quot;
    }
}</pre>
</div>
        </div>

       </div>
      </p>
      <p class="para">
       Since version 1.5.0 automatic and silent failover is disabled for the
       duration of a transaction. If the boundaries of a transaction have been
       properly detected, transaction stickiness is enabled and a server fails,
       the plugin will not attempt to fail over to the next server, if any, regardless
       of the failover policy configured. The user must handle the error
       manually. Depending on the configuration, the plugin may emit
       an error of type <em>E_WARNING</em> reading like
       <em>(mysqlnd_ms) Automatic failover is not permitted in the middle of a transaction</em>.
       This error may then be overwritten by follow up errors such as
       <em>(mysqlnd_ms) No connection selected by the last filter</em>.
       Those errors will be generated by the failing query function.
      </p>
      <p class="para">
       <div class="example" id="example-2307">
        <p><strong>Example #31 No automatic failover, error handling pitfall</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;assumption:&nbsp;automatic&nbsp;failover&nbsp;configured&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;sets&nbsp;plugin&nbsp;internal&nbsp;state&nbsp;in_trx&nbsp;=&nbsp;1&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">autocommit</span><span style="color: #007700">(</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;assumption:&nbsp;server&nbsp;fails&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!(</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;'Assume&nbsp;this&nbsp;query&nbsp;fails'&nbsp;AS&nbsp;_msg&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;</span><span style="color: #FF8000">/*&nbsp;handle&nbsp;failure&nbsp;of&nbsp;transaction,&nbsp;plugin&nbsp;internal&nbsp;state&nbsp;is&nbsp;still&nbsp;in_trx&nbsp;=&nbsp;1&nbsp;*/<br />&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">);<br />&nbsp;</span><span style="color: #FF8000">/*<br />&nbsp;&nbsp;If&nbsp;using&nbsp;autocommit()&nbsp;based&nbsp;transaction&nbsp;detection&nbsp;it&nbsp;is&nbsp;a<br />&nbsp;&nbsp;MUST&nbsp;to&nbsp;call&nbsp;autocommit(true).&nbsp;Otherwise&nbsp;the&nbsp;plugin&nbsp;assumes<br />&nbsp;&nbsp;the&nbsp;current&nbsp;transaction&nbsp;continues&nbsp;and&nbsp;connection<br />&nbsp;&nbsp;changes&nbsp;remain&nbsp;forbidden.<br />&nbsp;*/<br />&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">autocommit</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />&nbsp;</span><span style="color: #FF8000">/*&nbsp;Likewise,&nbsp;you'll&nbsp;want&nbsp;to&nbsp;start&nbsp;a&nbsp;new&nbsp;transaction&nbsp;*/<br />&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">autocommit</span><span style="color: #007700">(</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br />}<br /></span><span style="color: #FF8000">/*&nbsp;latin1&nbsp;used&nbsp;from&nbsp;now&nbsp;on&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set_charset</span><span style="color: #007700">(</span><span style="color: #DD0000">"latin1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
         </div>

       </div>
      </p>
      <p class="para">
       If a server fails in the middle of a transaction the
       plugin continues to refuse to switch connections until the
       current transaction has been finished. Recall
       that the plugin monitors API calls to detect transaction
       boundaries. Thus, you have to, for example, enable
       auto commit mode to end the current transaction before
       the plugin continues load balancing and switches the server.
       Likewise, you will want to start a new transaction
       immediately thereafter and disable auto commit mode again.
      </p>
      <p class="para">
       Not handling failed queries and not ending a failed transaction
       using API calls may cause all following commands emit errors
       such as  <em>Commands out of sync; you can&#039;t run this command now</em>.
       Thus, it is important to handle all errors.
      </p>
     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.transient_error">
       <code class="parameter">transient_error</code>
       <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
       The setting has been introduced in 1.6.0.
      </p>
      <p class="para">
       A database cluster node may reply a transient error to a client. The client
       can then repeat the operation on the same node, fail over to a different node
       or abort the operation. Per definition is it safe for a client to
       retry the same operation on the same node before giving up.
      </p>
      <p class="para">
       <em>PECL/mysqlnd_ms</em> can perform the retry
       loop on behalf of the application.
       By configuring <em>transient_error</em> the plugin can be
       instructed to repeat operations failing with a certain error code for
       a certain maximum number of times with a pause between the retries.
       If the transient error disappears during loop execution, it is
       hidden from the application. Otherwise, the error is
       forwarded to the application by the end of the loop.
      </p>
      <p class="para">
       <div class="example" id="example-2308">
        <p><strong>Example #32 Retry loop for transient errors</strong></p>
        <div class="example-contents">
<div class="inicode"><pre class="inicode">{
    &quot;myapp&quot;: {
        &quot;master&quot;: {
            &quot;master_0&quot;: {
                &quot;host&quot;: &quot;localhost&quot;
            }
        },
        &quot;slave&quot;: {
            &quot;slave_0&quot;: {
                &quot;host&quot;: &quot;192.168.78.136&quot;,
                &quot;port&quot;: &quot;3306&quot;
            }
       },
       &quot;transient_error&quot;: {
          &quot;mysql_error_codes&quot;: [
            1297
          ],
          &quot;max_retries&quot;: 2,
          &quot;usleep_retry&quot;: 100
       }
    }
}</pre>
</div>
        </div>

      </div>
     </p>
      <table class="doctable informaltable">
       
        <col width="1*" />
        <col width="7*" />
        <col width="2*" />
        <thead>
         <tr>
          <th>Keyword</th>
          <th>Description</th>
          <th>Version</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>
           <em>mysql_error_codes</em>
          </td>
          <td>
           <p class="para">
            List of transient error codes. You may add any MySQL error code
            to the list. It is possible to consider any error as transient
            not only <em>1297</em>
            (<em>HY000 (ER_GET_TEMPORARY_ERRMSG),
            Message: Got temporary error %d &#039;%s&#039; from %s</em>).
            Before adding other codes but <em>1297</em> to the list,
            make sure your cluster supports a new attempt without impacting
            the state of your application.
           </p>
          </td>
          <td>Since 1.6.0.</td>
         </tr>

         <tr>
          <td>
           <em>max_retries</em>
          </td>
          <td>
           <p class="para">
            How often to retry an operation which
            fails with a transient error before forwarding the
            failure to the user.
           </p>
           <p class="para">
             Default: <em>1</em>
           </p>
          </td>
          <td>Since 1.6.0.</td>
         </tr>

         <tr>
          <td>
           <em>usleep_retry</em>
          </td>
          <td>
           <p class="para">
            Milliseconds to sleep between transient error retries.
            The value is passed to the C function <span class="function"><a href="function.usleep.html" class="function">usleep()</a></span>,
            hence the name.
           </p>
           <p class="para">
             Default: <em>100</em>
           </p>
          </td>
          <td>Since 1.6.0.</td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    

    
     <dt id="ini.mysqlnd-ms-plugin-config-v2.xa">
       <code class="parameter">xa</code>
       <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
     </dt>

     <dd>

      <p class="para">
       The setting has been introduced in 1.6.0.
      </p>
      <p class="para">
       <blockquote class="note"><p><strong class="note">Note</strong>: 
        <strong>Experimental</strong><br />
        <p class="para">
         The feature is currently under development. There may be issues and/or
         feature limitations. Do not use in production environments.
        </p>
       </p></blockquote>
      </p>
      <dl>

       
        <dt>
state_store</dt>

        <dd>

           <dl>

            
             <dt>
record_participant_credentials</dt>

             <dd>

              <p class="para">
               Whether to store the username and password of a global transaction
               participant in the participants table. If disabled, the garbage
               collection will use the default username and password when connecting
               to the participants. Unless you are using a different username and
               password for each of your MySQL servers, you can use the default
               and avoid storing the sensible information in state store.
              </p>
              <p class="para">
               Please note, username and password are stored in clear text when using
               the MySQL state store, which is the only one available. It is in your
               responsibility to protect this sensible information.
              </p>
              <p class="para">
               Default: <em>false</em>
              </p>
             </dd>

            
            
             <dt>
participant_localhost_ip</dt>

             <dd>

              <p class="para">
               During XA garbage collection the plugin may find a participant server
               for which the host <em>localhost</em>
               has been recorded. If the garbage collection takes place on another host
               but the host that has written the participant record to the state store,
               the host name <em>localhost</em> now resolves to a different
               host. Therefore, when recording a participant servers host name
               in the state store, a value of <em>localhost</em> must
               be replaced with the actual IP address of <em>localhost</em>.
              </p>
              <p class="para">
               Setting <em>participant_localhost_ip</em> should be considered
               only if using <em>localhost</em> cannot be avoided.
               From a garbage collection point of view only, it is preferrable not to
               configure any socket connection but to provide an IP address and port
               for a node.
              </p>
             </dd>

            
            
             <dt>
mysql</dt>

             <dd>

              <p class="para">
               The MySQL state store is the only state store available.
              </p>
              <dl>

               
                <dt>
global_trx_table</dt>

                <dd>

                 <p class="para">
                  Name of the MySQL table used to store the state of an ongoing or aborted
                  global transaction. Use the below SQL statement to create the table.
                  Make sure to edit the table name to match your configuration.
                 </p>
                 <p class="para">
                  Default: <em>mysqlnd_ms_xa_trx</em>
                 </p>
                 <p class="para">
                  <div class="example" id="example-2309">
                   <p><strong>Example #33 SQL definition for the MySQL state store transaction table</strong></p>
                   <div class="example-contents">
<div class="sqlcode"><pre class="sqlcode">CREATE TABLE mysqlnd_ms_xa_trx (
  store_trx_id int(11) NOT NULL AUTO_INCREMENT,
  gtrid int(11) NOT NULL,
  format_id int(10) unsigned NOT NULL DEFAULT &#039;1&#039;,
  state enum(&#039;XA_NON_EXISTING&#039;,&#039;XA_ACTIVE&#039;,&#039;XA_IDLE&#039;,&#039;XA_PREPARED&#039;,&#039;XA_COMMIT&#039;,&#039;XA_ROLLBACK&#039;) NOT NULL DEFAULT &#039;XA_NON_EXISTING&#039;,
  intend enum(&#039;XA_NON_EXISTING&#039;,&#039;XA_ACTIVE&#039;,&#039;XA_IDLE&#039;,&#039;XA_PREPARED&#039;,&#039;XA_COMMIT&#039;,&#039;XA_ROLLBACK&#039;) DEFAULT &#039;XA_NON_EXISTING&#039;,
  finished enum(&#039;NO&#039;,&#039;SUCCESS&#039;,&#039;FAILURE&#039;) NOT NULL DEFAULT &#039;NO&#039;,
  modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  started datetime DEFAULT NULL,
  timeout datetime DEFAULT NULL,
  PRIMARY KEY (store_trx_id),
  KEY idx_xa_id (gtrid,format_id,finished),
  KEY idx_state (state)
) ENGINE=InnoDB</pre>
</div>
                   </div>

                  </div>
                 </p>
                </dd>

               
                 
                  <dt>
participant_table</dt>

                  <dd>

                   <p class="para">
                    Name of the MySQL table used to store participants of an ongoing or aborted
                    global transaction. Use the below SQL statement to create the table.
                    Make sure to edit the table name to match your configuration.
                   </p>
                   <p class="para">
                    Storing credentials can be enabled and disabled using
                    <em>record_participant_credentials</em>
                   </p>
                   <p class="para">
                    Default: <em>mysqlnd_ms_xa_participants</em>
                   </p>
                   <div class="example" id="example-2310">
                    <p><strong>Example #34 SQL definition for the MySQL state store transaction table</strong></p>
                    <div class="example-contents">
<div class="sqlcode"><pre class="sqlcode">CREATE TABLE mysqlnd_ms_xa_participants (
  fk_store_trx_id int(11) NOT NULL,
  bqual varbinary(64) NOT NULL DEFAULT &#039;&#039;,
  participant_id int(10) unsigned NOT NULL AUTO_INCREMENT,
  server_uuid varchar(127) DEFAULT NULL,
  scheme varchar(1024) NOT NULL,
  host varchar(127) DEFAULT NULL,
  port smallint(5) unsigned DEFAULT NULL,
  socket varchar(127) DEFAULT NULL,
  user varchar(127) DEFAULT NULL,
  password varchar(127) DEFAULT NULL,
  state enum(&#039;XA_NON_EXISTING&#039;,&#039;XA_ACTIVE&#039;,&#039;XA_IDLE&#039;,&#039;XA_PREPARED&#039;,&#039;XA_COMMIT&#039;,&#039;XA_ROLLBACK&#039;)
   NOT NULL DEFAULT &#039;XA_NON_EXISTING&#039;,
  health enum(&#039;OK&#039;,&#039;GC_DONE&#039;,&#039;CLIENT ERROR&#039;,&#039;SERVER ERROR&#039;) NOT NULL DEFAULT &#039;OK&#039;,
  connection_id int(10) unsigned DEFAULT NULL,
  client_errno smallint(5) unsigned DEFAULT NULL,
  client_error varchar(1024) DEFAULT NULL,
  modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (participant_id),
  KEY idx_xa_bqual (bqual),
  KEY idx_store_trx (fk_store_trx_id),
  CONSTRAINT mysqlnd_ms_xa_participants_ibfk_1 FOREIGN KEY (fk_store_trx_id)
    REFERENCES mysqlnd_ms_xa_trx (store_trx_id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB</pre>
</div>
                    </div>

                  </div>
                 </dd>

                
                
                 <dt>
garbage_collection_table</dt>

                 <dd>

                  <p class="para">
                   Name of the MySQL table used to track and synchronize garbage collection runs.
                   Use the below SQL statement to create the table.
                   Make sure to edit the table name to match your configuration.
                  </p>
                  <p class="para">
                   Default: <em>mysqlnd_ms_xa_gc</em>
                  </p>
                  <div class="example" id="example-2311">
                   <p><strong>Example #35 SQL definition for the MySQL state store garbage collection table</strong></p>
                   <div class="example-contents">
<div class="sqlcode"><pre class="sqlcode">CREATE TABLE mysqlnd_ms_xa_gc (
  gc_id int(10) unsigned NOT NULL AUTO_INCREMENT,
  gtrid int(11) NOT NULL,
  format_id int(10) unsigned NOT NULL DEFAULT &#039;1&#039;,
  fk_store_trx_id int(11) DEFAULT NULL,
  modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  attempts smallint(5) unsigned NOT NULL DEFAULT &#039;0&#039;,
  PRIMARY KEY (gc_id),
  KEY idx_store_trx (gtrid,format_id,fk_store_trx_id)
) ENGINE=InnoDB</pre>
</div>
                   </div>

                  </div>
                 </dd>

                
               
                <dt>
host</dt>

                <dd>

                 <p class="para">
                  Host name of the MySQL server.
                 </p>
                </dd>

               
               
                <dt>
user</dt>

                <dd>

                 <p class="para">
                  Name of the user used to connect to the MySQL server.
                 </p>
                </dd>

               
               
                <dt>
password</dt>

                <dd>

                 <p class="para">
                  Password for the MySQL server user.
                 </p>
                </dd>

               
               
                <dt>
db</dt>

                <dd>

                 <p class="para">
                  Database that holds the garbage collection tables.
                  Please note, you have to create the garbage collection
                  tables prior to using the plugin. The tables will not be
                  created implicitly during runtime but garbage collection
                  will fail if the tables to not exist.
                 </p>
                </dd>

               
               
                <dt>
port</dt>

                <dd>

                 <p class="para">
                  Port of the MySQL server.
                 </p>
                </dd>

               
               
                <dt>
socket</dt>

                <dd>

                 <p class="para">
                  Unix domain socket of the MySQL server. Please note,
                  if you have multiple PHP servers each of them will
                  try to carry out garbage collection and need to be able
                  to connect to the state store. In this case, you may
                  prefer configuring an IP address and a port for
                  the MySQL state store server to ensure all PHP servers
                  can reach it.
                 </p>
                </dd>

               
              </dl>

             </dd>

            
           </dl>

          </dd>

         
         
          <dt>
rollback_on_close</dt>

          <dd>

           <p class="para">
            Whether to automatically rollback an open global transaction when
            a connection is closed. If enabled, it mimics the default behaviour
            of local transactions. Should a client disconnect, the server rolls
            back any open and unfinished transactions.
           </p>
           <p class="para">
            Default: <em>true</em>
           </p>
          </dd>

         
         
          <dt id="ini.mysqlnd-ms-plugin-config-v2.xa.gc">garbage_collection</dt>

          <dd>

           <dl>

            
             <dt>
max_retries</dt>

             <dd>

              <p class="para">
               Maximum number of garbage collection runs before giving up.
               Allowed values are from <em>0</em> to <em>100</em>.
               A setting of <em>0</em> means no limit, unless
               the state store enforces a limit. Should the state store enforce a limit,
               it can be supposed to be significantly higher than <em>100</em>.
               Available since 1.6.0.
              </p>
              <p class="para">
               Please note, it is important to end failed XA
               transactions within reasonable time to make participating servers
               free resources bound to the transaction. The built-in garbage
               collection is not expected to fail for a long period as
               long as crashed servers become available again quickly.
               Still, a situation may arise where a human is required to
               act because the built-in garbage collection stopped or failed.
               In this case, you may first want to check if the transaction still
               cannot be fixed by forcing <span class="function"><a href="function.mysqlnd-ms-xa-gc.html" class="function">mysqlnd_ms_xa_gc()</a></span>
               to ignore the setting, prior to handling it manually.
              </p>
              <p class="para">
               Default: <em>5</em>
              </p>
             </dd>

            
            
             <dt>
probability</dt>

             <dd>

              <p class="para">
               Garbage collection probability.
               Allowed values are from <em>0</em> to <em>1000</em>.
               A setting of <em>0</em> disables automatic background
               garbage collection. Despite a setting of <em>0</em> it is
               still possible to trigger garbage collection by calling
               <span class="function"><strong>mysqlnd_ms_gc()</strong></span>.
               Available since 1.6.0.
              </p>
              <p class="para">
               The automatic garbage collection of stalled XA transaction is only
               available if a state store have been configured. The state store
               is responsible to keep track of XA transactions. Based on its recordings
               it can find blocked XA transactions where the client has crashed,
               connect to the participants and rollback the unfinished transactions.
              </p>
              <p class="para">
               The garbage collection is triggered as part of PHP&#039;s request shutdown
               procedure at the end of a web request. That is after your PHP script
               has finished working. Do decide whether to run the garbage collection
               a random value between <em>0</em> and <em>1000</em>
               is computed. If the <em>probability</em> value is higher
               or equal to the random value, the state stores garbage collection routines
               are invoked.
              </p>
              <p class="para">
               Default: <em>5</em>
              </p>
             </dd>

            
            
             <dt>
max_transactions_per_run</dt>

             <dd>

              <p class="para">
               Maximum number of unfinished XA transactions considered
               by the garbage collection during one run.
               Allowed values are from <em>1</em> to <em>32768</em>.
               Available since 1.6.0.
              </p>
              <p class="para">
               Cleaning up an unfinished XA transaction takes considerable
               amounts of time and resources. The garbage collection routine
               may have to connect to several participants of a failed global
               transaction to issue the SQL commands for rolling back
               the unfinished tranaction.
              </p>
              <p class="para">
               Default: <em>100</em>
              </p>
             </dd>

            
           </dl>

          </dd>

         
        </dl>

       </dd>

      
     </dl>

    </p>
   </div>

 <div class="section" id="mysqlnd-ms.plugin-ini-v1">
  <h2 class="title">Plugin configuration file (&lt;= 1.0.x)</h2>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    The below description applies to PECL/mysqlnd_ms &lt; 1.1.0-beta.
    It is not valid for later versions.
   </p>
  </p></blockquote>
  <p class="para">
   The plugin is using its own configuration file. The configuration file
   holds information on the MySQL replication master server,
   the MySQL replication slave servers, the server pick (load balancing) policy,
   the failover strategy and the use of lazy connections.
  </p>
  <p class="para">
   The PHP configuration directive
   <a href="mysqlnd-ms.configuration.html#ini.mysqlnd-ms.ini-file" class="link"><em>mysqlnd_ms.ini_file</em></a>
   is used to set the plugins configuration file.
  </p>
  <p class="para">
   The configuration file mimics standard the <em>php.ini</em> format.
   It consists of one or more sections. Every section defines its own unit
   of settings. There is no global section for setting defaults.
  </p>
  <p class="para">
   Applications reference sections by their name. Applications use section names
   as the host (server) parameter to the various connect methods of the
   <a href="ref.mysqli.html" class="link">mysqli</a>,
   <a href="ref.mysql.html" class="link">mysql</a> and
   <a href="ref.pdo-mysql.html" class="link">PDO_MYSQL</a> extensions. Upon connect
   the <a href="book.mysqlnd.html" class="link">mysqlnd</a> plugin compares the hostname
   with all section names from the plugin configuration file. If hostname and
   section name match, the plugin will load the sections settings.
  </p>
  <p class="para">
   <div class="example" id="example-2312">
    <p><strong>Example #36 Using section names example</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">[myapp]
master[] = localhost
slave[] = 192.168.2.27
slave[] = 192.168.2.28:3306
[localhost]
master[] = localhost:/tmp/mysql/mysql.sock
slave[] = 192.168.3.24:3305
slave[] = 192.168.3.65:3309</pre>
</div>
    </div>

    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;All&nbsp;of&nbsp;the&nbsp;following&nbsp;connections&nbsp;will&nbsp;be&nbsp;load&nbsp;balanced&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pdo&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysql:host=myapp;dbname=database'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'username'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'password'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Section names are strings. It is valid to use a section name such as
   <em>192.168.2.1</em>, <em>127.0.0.1</em> or
   <em>localhost</em>. If, for example, an application
   connects to <em>localhost</em> and a plugin
   configuration section <em>[localhost]</em> exists, the
   semantics of the connect operation are changed. The application will
   no longer only use the MySQL server running on the host
   <em>localhost</em> but the plugin will start to load balance
   MySQL queries following the rules from the <em>[localhost]</em>
   configuration section. This way you can load balance queries from
   an application without changing the applications source code.
  </p>
  <p class="para">
   The <em>master[]</em>, <em>slave[]</em>
   and <em>pick[]</em> configuration directives use a list-like syntax.
   Configuration directives supporting list-like syntax may appear multiple
   times in a configuration section. The plugin maintains the order in
   which entries appear when interpreting them. For example,
   the below example shows two <em>slave[]</em> configuration
   directives in the configuration section <em>[myapp]</em>.
   If doing round-robin load balancing for read-only queries, the plugin
   will send the first read-only query to the MySQL server
   <em>mysql_slave_1</em> because it is the first in the list.
   The second read-only query will be send to the MySQL server
   <em>mysql_slave_2</em> because it is the second in the list.
   Configuration directives supporting list-like syntax result are ordered
   from top to bottom in accordance to their appearance within a configuration
   section.
  </p>
  <p class="para">
   <div class="example" id="example-2313">
    <p><strong>Example #37 List-like syntax</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">[myapp]
master[] = mysql_master_server
slave[] = mysql_slave_1
slave[] = mysql_slave_2</pre>
</div>
    </div>

    </div>
  </p>
  <p class="para">
   Here is a short explanation of the configuration directives that can be used.
  </p>
  <p class="para">
  <dl>

   
     <dt id="ini.mysqlnd-ms-plugin-config.master">
      <code class="parameter">master[]</code>
      <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
     </dt>

     <dd>

      <p class="para">
       URI of a MySQL replication master server. The URI follows the syntax
       <em>hostname[:port|unix_domain_socket]</em>.
      </p>
      <p class="para">
       The plugin supports using only one master server.
      </p>
      <p class="para">
       Setting a master server is mandatory. The plugin will report a
       warning upon connect if the user has failed to provide a master
       server for a configuration section.
       The warning may read
       <em>(mysqlnd_ms) Cannot find master section in config</em>.
       Furthermore the plugin may set an error code for the connection handle such as
       <em>HY000/2000 (CR_UNKNOWN_ERROR)</em>. The corresponding error
       message depends on your language settings.
      </p>
     </dd>

    
    
    <dt id="ini.mysqlnd-ms-plugin-config.slave">
      <code class="parameter">slave[]</code>
      <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
     </dt>

     <dd>

      <p class="para">
       URI of one or more MySQL replication slave servers. The URI follows the syntax
       <em>hostname[:port|unix_domain_socket]</em>.
      </p>
      <p class="para">
       The plugin supports using one or more slave servers.
      </p>
      <p class="para">
       Setting a slave server is mandatory. The plugin will report a
       warning upon connect if the user has failed to provide at least one slave
       server for a configuration section. The warning may read
       <em>(mysqlnd_ms) Cannot find slaves section in config</em>.
       Furthermore the plugin may set an error code for the connection handle such as
       <em>HY000/2000 (CR_UNKNOWN_ERROR)</em>. The corresponding error
       message depends on your language settings.
      </p>
     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config.pick">
      <code class="parameter">pick[]</code>
      <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
     </dt>

     <dd>

      <p class="para">
       Load balancing (server picking) policy. Supported policies:
       <em>random</em>, <em>random_once</em> (default),
       <em>roundrobin</em>, <em>user</em>.
      </p>
      <p class="para">
       If no load balancing policy is set, the plugin will default to
       <em>random_once</em>. The <em>random_once</em>
       policy picks a random slave server when running the first read-only
       statement. The slave server will be used for all read-only
       statements until the PHP script execution ends.
      </p>
     <p class="para">
       The <em>random</em> policy will pick a random server whenever
       a read-only statement is to be executed.
     </p>
     <p class="para">
       If using
       <em>roundrobin</em> the plugin iterates over the list of
       configured slave servers to pick a server for statement execution.
       If the plugin reaches the end of the list, it wraps around to the beginning
       of the list and picks the first configured slave server.
      </p>
      <p class="para">
       Setting more than one load balancing policy for a configuration
       section makes only sense in conjunction with <em>user</em>
       and <span class="function"><a href="function.mysqlnd-ms-set-user-pick-server.html" class="function">mysqlnd_ms_set_user_pick_server()</a></span>. If the
       user defined callback fails to pick a server, the plugin falls
       back to the second configured load balancing policy.
      </p>
     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config.failover">
      <code class="parameter">failover</code>
      <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
     </dt>

     <dd>

      <p class="para">
       Failover policy. Supported policies:
       <em>disabled</em> (default), <em>master</em>.
      </p>
      <p class="para">
       If no failover policy is set, the plugin will not do any
       automatic failover (<em>failover=disabled</em>). Whenever
       the plugin fails to connect a server it will emit a warning and
       set the connections error code and message. Thereafter it is up to
       the application to handle the error and, for example, resent the
       last statement to trigger the selection of another server.
      </p>
      <p class="para">
       If using <em>failover=master</em> the plugin will implicitly
       failover to a slave, if available. Please check the
       concepts documentation to learn about potential
       pitfalls and risks of using <em>failover=master</em>.
      </p>
     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config.lazy-connections">
      <code class="parameter">lazy_connections</code>
      <span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span>
     </dt>

     <dd>

      <p class="para">
       Controls the use of lazy connections. Lazy connections
       are connections which are not opened before the client sends the first
       connection.
      </p>
      <p class="para">
       It is strongly recommended to use lazy connections.
       Lazy connections help to keep the number of open connections low.
       If you disable lazy connections and, for example, configure one MySQL
       replication master server and two MySQL replication slaves, the
       plugin will open three connections upon the first call to a
       connect function although the application might use the master
       connection only.
      </p>
      <p class="para">
       Lazy connections bare a risk if you make heavy use of actions
       which change the state of a connection. The plugin does not dispatch
       all state changing actions to all connections from the connection pool.
       The few dispatched actions are applied to already opened connections
       only. Lazy connections opened in the future are not affected.
       If, for example, the connection character set is changed using a
       PHP MySQL API call, the plugin will change the character set of all
       currently opened connection. It will not remember the character set
       change to apply it on lazy connections opened in the future. As a
       result the internal connection pool would hold connections using
       different character sets. This is not desired. Remember that character
       sets are taken into account for escaping.
      </p>
     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config.master-on-write">
      <code class="parameter">master_on_write</code>
      <span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span>
     </dt>

     <dd>

      <p class="para">
       If set, the plugin will use the master server only after the
       first statement has been executed on the master. Applications
       can still send statements to the slaves using SQL hints to
       overrule the automatic decision.
      </p>
      <p class="para">
       The setting may help with replication lag. If an application runs
       an <em>INSERT</em> the plugin will, by default, use the
       master to execute all following statements, including
       <em>SELECT</em> statements. This helps to avoid problems
       with reads from slaves which have not replicated the
       <em>INSERT</em> yet.
      </p>
     </dd>

    
    
     <dt id="ini.mysqlnd-ms-plugin-config.trx-stickiness">
      <code class="parameter">trx_stickiness</code>
      <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
     </dt>

     <dd>

      <p class="para">
       Transaction stickiness policy. Supported policies:
       <em>disabled</em> (default), <em>master</em>.
      </p>
      <p class="para">
       Experimental feature.
      </p>
      <p class="para">
       The setting requires 5.4.0 or newer. If used with PHP older than 5.4.0,
       the plugin will emit a warning like
       <em>(mysqlnd_ms) trx_stickiness strategy is not supported before PHP 5.3.99</em>.
      </p>
      <p class="para">
       If no transaction stickiness policy is set or,
       if setting <em>trx_stickiness=disabled</em>,
       the plugin is not transaction aware. Thus, the plugin may load balance
       connections and switch connections in the middle of a transaction.
       The plugin is not transaction safe. SQL hints must be used
       avoid connection switches during a transaction.
      </p>
      <p class="para">
       As of PHP 5.4.0 the mysqlnd library allows the plugin to monitor
       the <em>autocommit</em> mode set by calls to the
       libraries <em>trx_autocommit()</em> function.
       If setting <em>trx_stickiness=master</em> and
       <em>autocommit</em> gets disabled by a PHP MySQL extension
       invoking the <em>mysqlnd</em> library internal
       function call <em>trx_autocommit()</em>, the plugin is made
       aware of the begin of a transaction. Then, the plugin stops load balancing
       and directs all statements to the master server until
       <em>autocommit</em> is enabled. Thus, no SQL hints are required.
      </p>
      <p class="para">
       An example of a PHP MySQL API function calling the <em>mysqlnd</em>
       library internal function call <em>trx_autocommit()</em> is
       <span class="function"><a href="mysqli.autocommit.html" class="function">mysqli_autocommit()</a></span>.
      </p>
      <p class="para">
       Although setting <em>trx_stickiness=master</em>, the plugin
       cannot be made aware of <em>autocommit</em> mode changes caused
       by SQL statements such as <em>SET AUTOCOMMIT=0</em>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="section" id="mysqlnd-ms.testing">
  <h2 class="title">Testing</h2>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    The section applies to mysqlnd_ms 1.1.0 or newer, not the 1.0 series.
   </p>
  </p></blockquote>
  <p class="para">
   The PECL/mysqlnd_ms test suite is in the <var class="filename">tests/</var>
   directory of the source distribution. The test suite consists of standard
   phpt tests, which are described on the PHP Quality Assurance Teams website.
  </p>
  <p class="para">
   Running the tests requires setting up one to four MySQL servers. Some tests don&#039;t
   connect to MySQL at all. Others require one server for testing. Some require
   two distinct servers. In some cases two servers are used to emulate a
   replication setup. In other cases a master and a slave of an existing MySQL replication
   setup are required for testing. The tests will try to detect how many servers
   and what kind of servers are given. If the required servers are not found, the
   test will be skipped automatically.
  </p>
  <p class="para">
   Before running the tests, edit <var class="filename">tests/config.inc</var> to
   configure the MySQL servers to be used for testing.
  </p>
  <p class="para">
   The most basic configuration is as follows.
   <div class="example-contents">
<div class="cdata"><pre>
 putenv(&quot;MYSQL_TEST_HOST=localhost&quot;);
 putenv(&quot;MYSQL_TEST_PORT=3306&quot;);
 putenv(&quot;MYSQL_TEST_USER=root&quot;);
 putenv(&quot;MYSQL_TEST_PASSWD=&quot;);
 putenv(&quot;MYSQL_TEST_DB=test&quot;);
 putenv(&quot;MYSQL_TEST_ENGINE=MyISAM&quot;);
 putenv(&quot;MYSQL_TEST_SOCKET=&quot;);

 putenv(&quot;MYSQL_TEST_SKIP_CONNECT_FAILURE=1&quot;);
 putenv(&quot;MYSQL_TEST_CONNECT_FLAGS=0&quot;);
 putenv(&quot;MYSQL_TEST_EXPERIMENTAL=0&quot;);

 /* replication cluster emulation */
 putenv(&quot;MYSQL_TEST_EMULATED_MASTER_HOST=&quot;. getenv(&quot;MYSQL_TEST_HOST&quot;));
 putenv(&quot;MYSQL_TEST_EMULATED_SLAVE_HOST=&quot;. getenv(&quot;MYSQL_TEST_HOST&quot;));

 /* real replication cluster */
 putenv(&quot;MYSQL_TEST_MASTER_HOST=&quot;. getenv(&quot;MYSQL_TEST_EMULATED_MASTER_HOST&quot;));
 putenv(&quot;MYSQL_TEST_SLAVE_HOST=&quot;. getenv(&quot;MYSQL_TEST_EMULATED_SLAVE_HOST&quot;));
</pre></div>
     </div>

   </p>
   <p class="para">
    <em>MYSQL_TEST_HOST</em>, <em>MYSQL_TEST_PORT</em> and
    <em>MYSQL_TEST_SOCKET</em> define the hostname,
    TCP/IP port and Unix domain socket of the default database server.
    <em>MYSQL_TEST_USER</em> and <em>MYSQL_TEST_PASSWD</em>
    contain the user and password needed to connect to the database/schema
    configured with <em>MYSQL_TEST_DB</em>. All configured
    servers must  have the same database user configured to give access to
    the test database.
   </p>
   <p class="para">
    Using <em>host</em>, <em>host:port</em> or <em>host:/path/to/socket</em>
    syntax one can set an alternate  host, host and port or host and socket for any
    of the servers.
   <div class="example-contents">
<div class="cdata"><pre>
putenv(&quot;MYSQL_TEST_SLAVE_HOST=192.168.78.136:3307&quot;));
putenv(&quot;MYSQL_TEST_MASTER_HOST=myserver_hostname:/path/to/socket&quot;));
</pre></div>
     </div>

   </p>
 </div>

 <div class="section" id="mysqlnd-ms.debugging">
  <h2 class="title">Debugging and Tracing</h2>
  <p class="para">
   The mysqlnd debug log can be used to debug and trace the actitivities of
   PECL/mysqlnd_ms. As a mysqlnd PECL/mysqlnd_ms adds trace information to the
   mysqlnd library debug file. Please, see the
   <a href="mysqlnd.config.html#ini.mysqlnd.debug" class="link"><em>mysqlnd.debug</em></a>
   PHP configuration directive documentation for a detailed description
   on how to configure the debug log.
  </p>
  <p class="para">
  Configuration setting example to activate the debug log:
  <div class="example-contents">
<div class="cdata"><pre>
mysqlnd.debug=d:t:x:O,/tmp/mysqlnd.trace
</pre></div>
  </div>

  <blockquote class="note"><p><strong class="note">Note</strong>: 
    <p class="para">
     This feature is only available with a debug build of PHP. Works
     on Microsoft Windows if using a debug build of PHP and PHP was
     built using Microsoft Visual C version 9 and above.
    </p>
   </p></blockquote>
  </p>
  <p class="para">
   The debug log shows mysqlnd library and PECL/mysqlnd_ms plugin function calls,
   similar to a trace log. Mysqlnd library calls are usually prefixed with
   <em>mysqlnd_</em>. PECL/mysqlnd internal calls begin with
   <em>mysqlnd_ms</em>.
  </p>
  <p class="para">
   Example excerpt from the debug log (connect):
   <div class="example-contents">
<div class="cdata"><pre>
[...]
&gt;mysqlnd_connect
| info : host=myapp user=root db=test port=3306 flags=131072
| &gt;mysqlnd_ms::connect
| | &gt;mysqlnd_ms_config_json_section_exists
| | | info : section=[myapp] len=[5]
| | | &gt;mysqlnd_ms_config_json_sub_section_exists
| | | | info : section=[myapp] len=[5]
| | | | info : ret=1
| | | &lt;mysqlnd_ms_config_json_sub_section_exists
| | | info : ret=1
| | &lt;mysqlnd_ms_config_json_section_exists
[...]
</pre></div>
   </div>

  </p>
  <p class="para">
   The debug log is not only useful for plugin developers but also to find the
   cause of user errors. For example, if your application does not do proper
   error handling and fails to record error messages, checking the debug
   and trace log may help finding the cause. Use of the debug log
   to debug application issues should be considered only if no other
   option is available. Writing the debug log to disk is a slow
   operation and may have negative impact on the application
   performance.
  </p>
  <p class="para">
   Example excerpt from the debug log (connection failure):
   <div class="example-contents">
<div class="cdata"><pre>
[...]
| | | | | | | info : adding error [Access denied for user &#039;root&#039;@&#039;localhost&#039; (using password: YES)] to the list
| | | | | | | info : PACKET_FREE(0)
| | | | | | | info : PACKET_FREE(0x7f3ef6323f50)
| | | | | | | info : PACKET_FREE(0x7f3ef6324080)
| | | | | | &lt;mysqlnd_auth_handshake
| | | | | | info : switch_to_auth_protocol=n/a
| | | | | | info : conn-&gt;error_info.error_no = 1045
| | | | | &lt;mysqlnd_connect_run_authentication
| | | | | info : PACKET_FREE(0x7f3ef63236d8)
| | | | | &gt;mysqlnd_conn::free_contents
| | | | | | &gt;mysqlnd_net::free_contents
| | | | | | &lt;mysqlnd_net::free_contents
| | | | | | info : Freeing memory of members
| | | | | | info : scheme=unix:///tmp/mysql.sock
| | | | | | &gt;mysqlnd_error_list_pdtor
| | | | | | &lt;mysqlnd_error_list_pdtor
| | | | | &lt;mysqlnd_conn::free_contents
| | | | &lt;mysqlnd_conn::connect
[...]
</pre></div>
   </div>

  </p>
  <p class="para">
   The trace log can also be used to verify correct behaviour
   of PECL/mysqlnd_ms itself, for example, to check which server has been
   selected for query execution and why.
  </p>
  <p class="para">
   Example excerpt from the debug log (plugin decision):
   <div class="example-contents">
<div class="cdata"><pre>
[...]
&gt;mysqlnd_ms::query
| info : query=DROP TABLE IF EXISTS test
| &gt;_mysqlnd_plugin_get_plugin_connection_data
| | info : plugin_id=5
| &lt;_mysqlnd_plugin_get_plugin_connection_data
| &gt;mysqlnd_ms_pick_server_ex
| | info : conn_data=0x7fb6a7d3e5a0 *conn_data=0x7fb6a7d410d0
| | &gt;mysqlnd_ms_select_servers_all
| | &lt;mysqlnd_ms_select_servers_all
| | &gt;mysqlnd_ms_choose_connection_rr
| | | &gt;mysqlnd_ms_query_is_select
[...]
| | | &lt;mysqlnd_ms_query_is_select
[...]
| | | info : Init the master context
| | | info : list(0x7fb6a7d3f598) has 1
| | | info : Using master connection
| | | &gt;mysqlnd_ms_advanced_connect
| | | | &gt;mysqlnd_conn::connect
| | | | | info : host=localhost user=root db=test port=3306 flags=131072 persistent=0 state=0
</pre></div>
   </div>

  </p>
  <p class="para">
   In this case the statement <em>DROP TABLE IF EXISTS test</em> has been
   executed. Note that the statement string is shown in the log file. You may want
   to take measures to restrict access to the log for security considerations.
  </p>
  <p class="para">
    The statement has been load balanced using round robin policy,
    as you can easily guess from the functions name <em>&gt;mysqlnd_ms_choose_connection_rr</em>.
    It has been sent to a master server running on
    <em>host=localhost user=root db=test port=3306 flags=131072 persistent=0 state=0</em>.
  </p>
 </div>

 <div class="section" id="mysqlnd-ms.monitoring">
  <h2 class="title">Monitoring</h2>
  <p class="para">
   Plugin activity can be monitored using the mysqlnd trace log,
   mysqlnd statistics, mysqlnd_ms plugin statistics and external PHP debugging tools.
   Use of the trace log should be limited to debugging. It is recommended
   to use the plugins statistics for monitoring.
  </p>
  <p class="para">
   Writing a trace log is a slow operation. If using an external PHP debugging tool,
   please refer to the vendors manual about its performance impact and the
   type of information collected. In many cases, external debugging tools will
   provide call stacks. Often, a call stack or a trace log is more difficult to interpret
   than the statistics provided by the plugin.
  </p>
  <p class="para">
   Plugin statistics tell how often which kind of cluster node has been used (slave or master),
   why the node was used, if lazy connections have been used and if global transaction
   ID injection has been performed. The monitoring information provided enables
   user to verify plugin decisions and to plan their cluster resources based on usage pattern.
   The function <span class="function"><a href="function.mysqlnd-ms-get-stats.html" class="function">mysqlnd_ms_get_stats()</a></span>
   is used to access the statistics. Please, see the functions description for a list
   of available statistics.
  </p>
  <p class="para">
   Statistics are collected on a per PHP process basis. Their scope is a PHP process.
   Depending on the PHP deployment model a process may serve one or multiple web requests.
   If using CGI model, a PHP process serves one web request. If using FastCGI or
   pre-fork web server models, a PHP process usually serves multiple web requests.
   The same is the case with a threaded web server. Please, note that threads running
   in parallel can update the statistics in parallel. Thus, if using a threaded PHP
   deployment model, statistics can be changed by more than one script at a time. A
   script cannot rely on the fact that it sees only its own changes to statistics.
  </p>
  <p class="para">
   <div class="example" id="example-2314">
    <p><strong>Example #38 Verify plugin activity in a non-threaded deployment model</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">mysqlnd_ms.enable=1
mysqlnd_ms.collect_statistics=1</pre>
</div>
    </div>

    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Load&nbsp;balanced&nbsp;following&nbsp;"myapp"&nbsp;section&nbsp;rules&nbsp;from&nbsp;the&nbsp;plugins&nbsp;config&nbsp;file&nbsp;(not&nbsp;shown)&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">mysqli_connect_errno</span><span style="color: #007700">())<br />&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Of&nbsp;course,&nbsp;your&nbsp;error&nbsp;handling&nbsp;is&nbsp;nicer...&nbsp;*/<br />&nbsp;&nbsp;</span><span style="color: #007700">die(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqli_connect_errno</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">mysqli_connect_error</span><span style="color: #007700">()));<br /><br /></span><span style="color: #0000BB">$stats_before&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqlnd_ms_get_stats</span><span style="color: #007700">();<br />if&nbsp;(</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;'Read&nbsp;request'&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_all</span><span style="color: #007700">());<br />}<br /></span><span style="color: #0000BB">$stats_after&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqlnd_ms_get_stats</span><span style="color: #007700">();<br />if&nbsp;(</span><span style="color: #0000BB">$stats_after</span><span style="color: #007700">[</span><span style="color: #DD0000">'use_slave'</span><span style="color: #007700">]&nbsp;&lt;=&nbsp;</span><span style="color: #0000BB">$stats_before</span><span style="color: #007700">[</span><span style="color: #DD0000">'use_slave'</span><span style="color: #007700">])&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"According&nbsp;to&nbsp;the&nbsp;statistics&nbsp;the&nbsp;read&nbsp;request&nbsp;has&nbsp;not&nbsp;been&nbsp;run&nbsp;on&nbsp;a&nbsp;slave!"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Statistics are aggregated for all plugin activities and all connections handled by
   the plugin. It is not possible to tell how much a certain connection handle has
   contributed to the overall statistics.
  </p>
  <p class="para">
   Utilizing PHPs <span class="function"><a href="function.register-shutdown-function.html" class="function">register_shutdown_function()</a></span> function or the
   <em>auto_append_file</em> PHP configuration directive it is
   easily possible to dump statistics into, for example, a log file when a script
   finishes. Instead of using a log file it is also possible to send the statistics
   to an external monitoring tool for recording and display.
  </p>
  <p class="para">
   <div class="example" id="example-2315">
    <p><strong>Example #39 Recording statistics during shutdown</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">mysqlnd_ms.enable=1
mysqlnd_ms.collect_statistics=1
error_log=/tmp/php_errors.log</pre>
</div>
    </div>

    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">check_stats</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$msg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_repeat</span><span style="color: #007700">(</span><span style="color: #DD0000">"-"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">80</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$msg&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">mysqlnd_ms_get_stats</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$msg&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #0000BB">str_repeat</span><span style="color: #007700">(</span><span style="color: #DD0000">"-"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">80</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">register_shutdown_function</span><span style="color: #007700">(</span><span style="color: #DD0000">"check_stats"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div>
   </p>
  </div>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqlnd-ms.configuration.html">Runtime Configuration</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqlnd-ms.constants.html">Predefined Constants</a></div>
 <div class="up"><a href="mysqlnd-ms.setup.html">Installing/Configuring</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>