Predefined Constants
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
SQL hint related
Example #1 Example demonstrating the usage of mysqlnd_ms constants
The mysqlnd replication and load balancing plugin (mysqlnd_ms) performs read/write splitting. This directs write queries to a MySQL master server, and read-only queries to the MySQL slave servers. The plugin has a built-in read/write split logic. All queries which start with SELECT are considered read-only queries, which are then sent to a MySQL slave server that is listed in the plugin configuration file. All other queries are directed to the MySQL master server that is also specified in the plugin configuration file.
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 an SQL comment for certain commands, which then control query redirection. Other systems involved in the query processing are unaffected by the SQL hints because other systems will ignore the SQL comments.
The plugin supports three SQL hints to direct queries to either the MySQL slave servers, the MySQL master server, or the last used MySQL server. SQL hints must be placed at the beginning of a query to be recognized by the plugin.
For better portability, it is recommended to use the string constants
MYSQLND_MS_MASTER_SWITCH
,
MYSQLND_MS_SLAVE_SWITCH
and
MYSQLND_MS_LAST_USED_SWITCH
instead of their literal
values.
<?php
/* Use constants for maximum portability */
$master_query = "/*" . MYSQLND_MS_MASTER_SWITCH . "*/SELECT id FROM test";
/* Valid but less portable: using literal instead of constant */
$slave_query = "/*ms=slave*/SHOW TABLES";
printf("master_query = '%s'\n", $master_query);
printf("slave_query = '%s'\n", $slave_query);
?>
The above examples will output:
master_query = /*ms=master*/SELECT id FROM test slave_query = /*ms=slave*/SHOW TABLES
-
MYSQLND_MS_MASTER_SWITCH
(string) - SQL hint used to send a query to the MySQL replication master server.
-
MYSQLND_MS_SLAVE_SWITCH
(string) - SQL hint used to send a query to one of the MySQL replication slave servers.
-
MYSQLND_MS_LAST_USED_SWITCH
(string) - 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.
mysqlnd_ms_query_is_select() related
-
MYSQLND_MS_QUERY_USE_MASTER
(integer) -
If mysqlnd_ms_is_select() returns
MYSQLND_MS_QUERY_USE_MASTER
for a given query, the built-in read/write split mechanism recommends sending the query to a MySQL replication master server. -
MYSQLND_MS_QUERY_USE_SLAVE
(integer) -
If mysqlnd_ms_is_select() returns
MYSQLND_MS_QUERY_USE_SLAVE
for a given query, the built-in read/write split mechanism recommends sending the query to a MySQL replication slave server. -
MYSQLND_MS_QUERY_USE_LAST_USED
(integer) -
If mysqlnd_ms_is_select() returns
MYSQLND_MS_QUERY_USE_LAST_USED
for a given query, the built-in read/write split mechanism recommends sending the query to the last used server.
mysqlnd_ms_set_qos(), quality of service filter and service level related
-
MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL
(integer) - Use to request the service level eventual consistency from the mysqlnd_ms_set_qos(). Eventual consistency is the default quality of service when reading from an asynchronous MySQL replication slave. Data returned in this service level may or may not be stale, depending on whether the selected slaves happen to have replicated the latest changes from the MySQL replication master or not.
-
MYSQLND_MS_QOS_CONSISTENCY_SESSION
(integer) - Use to request the service level session consistency from the mysqlnd_ms_set_qos(). Session consistency is defined as read your writes. The client is guaranteed to see his latest changes.
-
MYSQLND_MS_QOS_CONSISTENCY_STRONG
(integer) - Use to request the service level strong consistency from the mysqlnd_ms_set_qos(). Strong consistency is used to ensure all clients see each others changes.
-
MYSQLND_MS_QOS_OPTION_GTID
(integer) - Used as a service level option with mysqlnd_ms_set_qos() to parameterize session consistency.
-
MYSQLND_MS_QOS_OPTION_AGE
(integer) - Used as a service level option with mysqlnd_ms_set_qos() to parameterize eventual consistency.
Other
The plugins version number can be obtained using
MYSQLND_MS_VERSION
or
MYSQLND_MS_VERSION_ID
.
MYSQLND_MS_VERSION
is the string representation of the numerical version number
MYSQLND_MS_VERSION_ID
, which is an integer such as 10000.
Developers can calculate the version number as follows.
Version (part) | Example |
---|---|
Major*10000 | 1*10000 = 10000 |
Minor*100 | 0*100 = 0 |
Patch | 0 = 0 |
MYSQLND_MS_VERSION_ID | 10000 |
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-mysqlnd-ms.constants.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.