php-doc-en/reference/mysqlnd_ms/constants.xml
Yannick Torres 57236796d1 Fix svn keywords
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@310337 c90b9560-bf6c-de11-be94-00142212c4b1
2011-04-19 05:22:45 +00:00

246 lines
6.9 KiB
XML
Executable file

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<appendix xml:id="mysqlnd-ms.constants" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.constants;
&extension.constants;
<para>
<emphasis role="bold">SQL hint related</emphasis>
</para>
<para>
<example>
<para>
The mysqlnd replication and load balancing plugin (<literal>mysqlnd_ms</literal>)
does read/write splitting to direct write queries to a MySQL master server and
read-only queries to MySQL slave servers in a MySQL replication setup.
The plugin has a built-in read/write split logic. The logic is very basic.
All queries which start with <literal>SELECT</literal> are considered read-only
queries which shall be send to a MySQL slave server listed in
the plugin configuration file. All other queries shall be directed to the
MySQL master server specified in the plugin configuration file.
</para>
<para>
User supplied SQL hints can be used to overrule automatic read/write splitting
to gain full control on the process. SQL hints are standards compliant
SQL comments. The plugin will scan the beginning of a query string for
a SQL comment with certain contents which control query redirection.
Other systems involved in the query processing are unaffected by the
plugins SQL hints because other systems will ignore the SQL comments.
</para>
<para>
The plugin supports three SQL hints to direct queries to the MySQL slave
servers, the MySQL master server and the last used MySQL server. SQL hints
must be placed at the beginning to be recognized by the plugin.
</para>
<para>
It is recommended to use the string constants
<constant>MYSQLND_MS_MASTER_SWITCH</constant>,
<constant>MYSQLND_MS_SLAVE_SWITCH</constant> and
<constant>MYSQLND_MS_LAST_USED_SWITCH</constant> instead of their literal
values for better portability.
</para>
<programlisting role="php">
<![CDATA[
<?php
/* Use constants for maximum portability */
$master_query = "/*" . MYSQLND_MS_MASTER_SWITCH . "*/SELECT id FROM test";
/* Valid but less portable: using literal instad of constant */
$slave_query = "/*ms=slave*/SHOW TABLES";
printf("master_query = '%s'\n", $master_query);
printf("slave_query = '%s'\n", $slave_query);
?>
]]>
</programlisting>
&examples.outputs;
<screen>
<![CDATA[
master_query = /*ms=master*/SELECT id FROM test
slave_query = /*ms=slave*/SHOW TABLES
]]>
</screen>
</example>
</para>
<para>
<variablelist>
<varlistentry>
<term>
<constant>MYSQLND_MS_MASTER_SWITCH</constant>
(<type>string</type>)
</term>
<listitem>
<simpara>
SQL hint used to send a query to the MySQL replication master server.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>MYSQLND_MS_SLAVE_SWITCH</constant>
(<type>string</type>)
</term>
<listitem>
<simpara>
SQL hint used to send a query to one of the MySQL replication slave servers.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>MYSQLND_MS_LAST_USED_SWITCH</constant>
(<type>string</type>)
</term>
<listitem>
<simpara>
SQL hint used to send a query to the last used MySQL server. The last
used MySQL server can either be a master or a slave server in a
MySQL replication setup.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<function>mysqlnd_ms_is_select</function> related
</para>
<para>
<variablelist>
<varlistentry>
<term>
<constant>MYSQLND_MS_QUERY_USE_MASTER</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
If <function>mysqlnd_ms_is_select</function> returns
<constant>MYSQLND_MS_QUERY_USE_MASTER</constant> for a given query, the
built-in read/write split mechanism recommends sending the query to
a MySQL replication master server.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>MYSQLND_MS_QUERY_USE_SLAVE</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
If <function>mysqlnd_ms_is_select</function> returns
<constant>MYSQLND_MS_QUERY_USE_SLAVE</constant> for a given query, the
built-in read/write split mechanism recommends sending the query to
a MySQL replication slave server.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>MYSQLND_MS_QUERY_USE_LAST_USED</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
If <function>mysqlnd_ms_is_select</function> returns
<constant>MYSQLND_MS_QUERY_USE_LAST_USED</constant> for a given query, the
built-in read/write split mechanism recommends sending the query to
the last used server.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<emphasis role="bold">Other</emphasis>
</para>
<para>
The plugins version number can be obtained using
<constant>MYSQLND_MS_VERSION</constant> or
<constant>MYSQLND_MS_VERSION_ID</constant>.
<constant>MYSQLND_MS_VERSION</constant>
is the string representation of the numerical version number
<constant>MYSQLND_MS_VERSION_ID</constant>, which is an integer such as 10000.
Developers can calculate the version number as follows.
</para>
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Version (part)</entry>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry>Major*10000</entry>
<entry>1*10000 = 10000</entry>
</row>
<row>
<entry>Minor*100</entry>
<entry>0*100 = 0</entry>
</row>
<row>
<entry>Patch</entry>
<entry>0 = 0</entry>
</row>
<row>
<entry>MYSQLND_MS_VERSION_ID</entry>
<entry>10000</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>
<variablelist>
<varlistentry>
<term>
<constant>MYSQLND_MS_VERSION</constant>
(<type>string</type>)
</term>
<listitem>
<simpara>
Plugin version string, for example, <quote>1.0.0-prototype</quote>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>MYSQLND_MS_VERSION_ID</constant>
(<type>integer</type>)
</term>
<listitem>
<simpara>
Plugin version number, for example, 10000.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</appendix>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->