mysqlnd_ms
在线手册:中文 英文
PHP手册

简介

The mysqlnd replication and load balancing plugin (mysqlnd_ms) adds easy to use MySQL replication support to all PHP MySQL extensions that use mysqlnd.

As of version PHP 5.3.3 the MySQL native driver for PHP (mysqlnd) features an internal plugin C API. C plugins, such as the replication and load balancing plugin, can extend the functionality of mysqlnd.

The MySQL native driver for PHP is a C library that ships together with PHP as of PHP 5.3.0. It serves as a drop-in replacement for the MySQL Client Library (libmysql/libmysqlclient). Using mysqlnd has several advantages: no extra downloads are required because it's bundled with PHP, it's under the PHP license, there is lower memory consumption in certain cases, and it contains new functionality such as asynchronous queries.

Mysqlnd plugins like mysqlnd_ms operate, for the most part, transparently from a user perspective. The replication and load balancing plugin supports all PHP applications, and all MySQL PHP extensions. It does not change existing APIs. Therefore, it can easily be used with existing PHP applications.

Note:

The mysqlnd replication and load balancing plugin is a beta plugin, and is not feature complete.

Key Features

The key features of PECL/mysqlnd_ms are as follows.

Limitations

The plugin does not support MySQL replication setups with more than one master server. The experimental configuration setting mysqlnd_ms.multi_master was introduced in version 1.1.0-beta, to help find ways to remove this limitation and to enable the use of synchronous clusters, such as MySQL Cluster.

The built-in read/write-split mechanism is very basic. Every query which starts with SELECT is considered a read request to be sent to a MySQL slave server. All other queries (such as SHOW statements) are considered as write requests that are sent to the MySQL master server. The build-in behavior can be overruled using SQL hints, or a user-defined callback function.

The read/write splitter is not aware of multi-statements. Multi-statements are considered as one statement. The decision of where to run the statement will be based on the beginning of the statement string. For example, if using mysqli_multi_query() to execute the multi-statement SELECT id FROM test ; INSERT INTO test(id) VALUES (1), the statement will be redirected to a slave server because it begins with SELECT. The INSERT statement, which is also part of the multi-statement, will not be redirected to a master server.

Prior to version 1.1.0-beta, the plugin did not support native prepared statements. Please note that PDO_MySQL uses client-side prepared statement emulation by default. Client-side emulated prepared statements are fully supported by any version of the replication and load balancing plugin because the emulation is not using native prepared statements. If you are using PHP based database abstraction, please consult the vendor manual to learn if a client-side prepared statement emulation is used.

Note:

Applications must be aware of the consequences of connection switches that are performed for load balancing purposes. Please check the documentation on connection pooling and switching, transaction handling, failover load balancingread-write splitting.

On the name

The shortcut mysqlnd_ms stands for mysqlnd master slave plugin. The name was chosen for a quick-and-dirty proof-of-concept. In the beginning the developers did not expect to continue using the code base.


mysqlnd_ms
在线手册:中文 英文
PHP手册